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,
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 ( ~).
When we run INSERT, UPDATE, and DELETE statements, we must use a square bracket or double quotes to handle the column name with space.
Names with spaces can be specified using backticks.
Column names can contain any valid characters (for example, spaces).
select * from States where [State Name] = 'Michigan';
Try throwing square brackets around it:
select * from States where [State Name] = 'Michigan';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With