When i use
SELECT order_id from `order` where `order_id`=U687678601
i get error
ERROR 1054: Unknown Column 'U687678601' in where clause
but when i type
SELECT order_id from`order` where `order_id`='U687678601'
it works fine..
I am using mysql.
I know its a novice question but can anyone explain why this is happening and can i add quotes programmatically and is it a good idea to add quote through code
Thanks
'U687678601' is a string (not a number), and not a field in your table; so it must be quoted.
Order is a reserverd keyword, you should use another name for your table. You could enclose the table name in quotes, like this:
And as for the quoting of values, if the value is of type string, you should use quotes always. If the value is some numeric type, you don't have to, but it won't do any harm to enclose virtually everything.
When we are supplying a string/varchar type to the SQL query we must specify it with the ''. and for the non varchar types no need to supply ''. Thats why your query works fine when u write
this shows that your order_id column contains the varchar type. so from now you should apply the following syntax to the SQL query:
or
and also consider that the ORDER is the reserved keyword .. so try to change the table name to other like order_table or else...