sql select语句给出列错误 [英] sql select statement giving column error

查看:101
本文介绍了sql select语句给出列错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆