I am working on a project where another developer created a table with column names like 'Business Name'
. That is a space between two words. If I run a SELECT
statement with 'Business Name' it says there is no column with name 'Business'.
How can I solve this problem?
I think double quotes works too:
SELECT "Business Name","Other Name" FROM your_Table
But I only tested on SQL Server NOT mySQL in case someone work with MS SQL Server.
You need to use backtick instead of single quotes:
Single quote - 'Business Name'
- Wrong
Backtick - `Business Name`
- Correct
If double quotes does not work , try including the string within square brackets.
For eg:
SELECT "Business Name","Other Name" FROM your_Table
can be changed as
SELECT [Business Name],[Other Name] FROM your_Table
I got here with an MS Access problem.
Backticks are good for MySQL, but they create weird errors, like "Invalid Query Name: Query1" in MS Access, for MS Access only, use square brackets:
It should look like this
SELECT Customer.[Customer ID], Customer.[Full Name] ...
To each his own but the right way to code this is to rename the columns inserting underscore so there are no gaps. This will ensure zero errors when coding. When printing the column names for public display you could search-and-replace to replace the underscore with a space.
Source: Stackoverflow.com