MySQL错误:"where子句"中的未知列 [英] MySQL error: Unknown column in 'where clause'

查看:345
本文介绍了MySQL错误:"where子句"中的未知列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为bank的表,该表具有三列:uidnickbalance.

I have a table called bank with three columns: uid, nick, balance.

我正在尝试创建一个查询,该查询将根据缺口返回余额,并且在使用此查询时出现错误Unknown column 'Alex' in 'where clause':

I am trying to create a query that will return the balance based on the nick, and I am getting an error Unknown column 'Alex' in 'where clause' when I use this query:

SELECT b.balance FROM bank AS b WHERE b.nick=`Alex` LIMIT 1

有人在这里看到我在做什么错吗?

Can anyone see what I am doing wrong here?

推荐答案

反引号(`)用于标识,例如表名,列名等.单引号(')用于字符串文字.

backticks (`) are used for identifiers, like table names, column names, etc. Single quotes(') are used for string literals.

您想这样做:

SELECT b.balance FROM bank AS b WHERE b.nick='Alex' LIMIT 1

或者,更明确地说:

SELECT `b`.`balance` FROM `bank` AS b WHERE `b`.`nick`='Alex' LIMIT 1

如果不存在歧义,并且表/列名称没有特殊字符或空格,则可以将`保留为空.

When there is no chance of ambiguity, and when table/column names do not have special characters or spaces, then you can leave the ` off.

这是一些干燥且难以阅读的文档: http: //dev.mysql.com/doc/refman/5.0/zh-CN/identifiers.html

Here is some documentation that is dry and hard to read: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

但这是有关dba.stackoverflow的一个相关问题,该问题更易于阅读:

But here is a related question on dba.stackoverflow that is easier to read: https://dba.stackexchange.com/questions/23129/benefits-of-using-backtick-in-mysql-queries

这是一个非常好的页面,我建议大家阅读:

And here is a very good page that I recommend everyone read: http://www.sitepoint.com/forums/showthread.php?408497-the-big-bad-thread-of-quot-MySQL-Best-Practices-and-Other-Useful-Information-quot

这篇关于MySQL错误:"where子句"中的未知列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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