0

I have 3 columns in Database tables. Id Operator , o.Id Country

select [o.Id Operator] as OperatorID,[o.Id Country] as countryid
from 
customersubscription cs inner join club cl on (cs.idclub = cl.idclub) 
inner join customer cu on (cs.idcustomer = cu.idcustomer)
inner join operator o on (cu.idoperator = o.idoperator) 
left outer join promoter p on (cs.idpromoter = p.id )
where 
cl.idproject in (3,19,23,24,27)

The two columns in the select sections have spaces in them. I used [ ] and tried as mentioned in the question here but didnt work.

4
  • 2
    Which database are you using here? MySQL and SQLite are similar, but SQL Server is the one that uses [...]. Honestly, spaces are super annoying, so the best way is to get rid of them and alter your schema. Commented Apr 9, 2017 at 6:17
  • I am not allowed to edit. Ihave read only access. Its MySQL Commented Apr 9, 2017 at 6:41
  • That's a tough break. Commented Apr 9, 2017 at 6:42
  • IS there any way to deal with it? Commented Apr 9, 2017 at 6:43

2 Answers 2

1

In MySQL any column name that isn't simple (composed of letters, numbers, and/or underscores) must be escaped:

SELECT o.`Id Operator` as OperatorID,
  o.`Id Country` as countryid

If you're calling the one OperatorID, the next should be CountryID for consistency's sake.

Sign up to request clarification or add additional context in comments.

8 Comments

[MySQL][ODBC 5.3(w) Driver][mysqld-5.6.31-log]Unknown column 'o.Id Operator' in 'field list'
Are you sure you put the backticks in the right place? Are you sure that's the right column name? You can check with DESCRIBE operator.
How do I check with the describe operator please?
Based on your question operator is the table in question. If you want a visual tool to help with this, MySQL Workbench is pretty good and free.
This is how you escape things. As to what's wrong, I don't know. Maybe that column's not right. Maybe it has two spaces.
|
0

You can quote column names with [/] in SQLite, but then anythying between the brackets will be part of the column name.

So the column name you a trying to use is o.Id Operator.

The period that separates the table name and the column name must not be quoted. And in MySQL, you must use backticks instead:

SELECT o.`Id Operator` ...

2 Comments

[MySQL][ODBC 5.3(w) Driver][mysqld-5.6.31-log]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[Id Operator] as OperatorID,o.[Id Country] as countryid, cl.name as project, cl.' at line 3
was lazy to type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.