Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reference a column with a space in the name?

Tags:

sql

I'm trying to run a statement where I retrieve tuples from a database. However my attribute has a space which is "State Name".

Im calling the SQL statement as follows:

select * from States where State Name = 'Michigan';

I'm pretty sure there is something wrong with the attribute having a space. How can I fix this problem without changing the name of the attribute? How can I call a SQL statement with the attribute constraint having a space?

Thanks,

like image 718
dksaldas Avatar asked May 12 '11 04:05

dksaldas


People also ask

How do I select a column with a space in a name?

To select a column name with spaces, use the back tick symbol with column name. The symbol is ( ` `). Back tick is displayed in the keyboard below the tilde operator ( ~).

How do you reference a column name with a space in SQL?

When we run INSERT, UPDATE, and DELETE statements, we must use a square bracket or double quotes to handle the column name with space.

How do I refer a column name with a space in R?

Names with spaces can be specified using backticks.

Can a column name have spaces?

Column names can contain any valid characters (for example, spaces).


2 Answers

select * from States where [State Name] = 'Michigan';
like image 73
Tushar Avatar answered Oct 01 '22 04:10

Tushar


Try throwing square brackets around it:

select * from States where [State Name] = 'Michigan';
like image 33
Abe Miessler Avatar answered Oct 01 '22 04:10

Abe Miessler