sql select语句给出列错误 [英] sql select statement giving column error
问题描述
当我使用
SELECT order_id from `order` where `order_id`=U687678601
我遇到错误
错误1054:未知列 where子句中的"U687678601"
ERROR 1054: Unknown Column 'U687678601' in where clause
但是当我键入
SELECT order_id from`order` where `order_id`='U687678601'
它工作正常..
我正在使用mysql.
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
谢谢
推荐答案
在向SQL查询提供字符串/varchar类型时,必须使用''进行指定. 对于非varchar类型,则无需提供. 这就是为什么当您编写
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'
这表明您的order_id列包含varchar类型.因此,从现在开始,您应该将以下语法应用于SQL查询:
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'
或
SELECT column_name,..... FROM table WHERE column_name = nonvarchar_value.
还要考虑ORDER是保留关键字..因此,尝试将表名更改为其他名称,例如order_table,否则...
and also consider that the ORDER is the reserved keyword .. so try to change the table name to other like order_table or else...
这篇关于sql select语句给出列错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!