Reputation: 1054
I am not able to run a simple select query with a where
clause.
I am using MySQL and have a column User ID
.
The problem is with the column name made of two words.
select * from user where 'User ID' = "xyz"
A usual query like the next one runs fine as expected:
select * from user where email = 'xyz'
How can I write a condition on the User ID
column?
Upvotes: 0
Views: 755
Reputation: 348
Like Jonathan Leffler pointed, if you are in MS SQL Server you can try:
select * from user where [User ID] = "xyz"
or in MySql PHP Admin:
select * from user where ´User ID´ = "xyz"
I am not sure about MySql, but in SQL Server, even "login" or "user" that are some reserved words, they are functional in queries normally. Despite, I think is better not to use that.
I hope this can help you or another one. Hugs.
Ref.:
1. Meaning of square brackets [] in MS-SQL table designer?
2. When to use single quotes, double quotes, and backticks in MySQL
Upvotes: 1
Reputation: 336
No way to rename this column ?
You can try with backticks around the column name in your query :
select * from user where `User ID` = 'xyz';
Upvotes: 1
Reputation: 6573
I think user is a reserved word...
Try:
SELECT *
FROM `user`
WHERE `email` = 'xyz';
Upvotes: -1
Reputation: 169284
Try:
SELECT u.*
FROM `user` u
WHERE u.`User ID` = 'xyz';
But in general, try not to use such column names.
Using backticks to qualify the table and/or column names is also useful if you have names that conflict with MySQL keywords, e.g. user
.
Upvotes: 2