sql select statement giving column error

被刻印的时光 ゝ 提交于 2019-12-02 08:53:31

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

SELECT order_id fromorder where order_id='U687678601'

this shows that your order_id column contains the varchar type. so from now you should apply the following syntax to the SQL query:

SELECT column_name,..... FROM table WHERE column_name = 'varchar_value'

or

SELECT column_name,..... FROM table WHERE column_name = nonvarchar_value.

and also consider that the ORDER is the reserved keyword .. so try to change the table name to other like order_table or else...

'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:

SELECT order_id from `order` where order_id=U687678601

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!