为什么这个简单的MySQL子查询不起作用?

时间:2011-04-07 02:32:59

标签: mysql sql

此查询与我显示的工作示例几乎完全相同:

SELECT * FROM entities.entities
    WHERE entities.entities.id =
        (SELET MAX(entities.entities.id) FROM entities.entities);

这个查询开始时要简单得多,但我一直在各处添加数据库和表名,以确保查询无可挑剔。

它产生了不那么有用的错误:

  

SQL错误(1064):您的SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在第3行使用“MAX(id)FROM entities”附近的正确语法

我已经确定我有MySQL版本5+,我确保子查询是一个标量子查询,即它只返回一行一行,并且在查询的WHERE部分中受支持。 / p>

我认为没有错。

输入专家!

4 个答案:

答案 0 :(得分:5)

您的代码应为:

SELECT * FROM entities.entities
WHERE entities.entities.id =
    (SELECT MAX(entities.entities.id) FROM entities.entities);

(你拼错了“SELECT”为“SELET。”)

答案 1 :(得分:1)

试试这个:

SELECT * FROM entities.entities
    WHERE entities.entities.id =
        (SELECT MAX(entities.entities.id) FROM entities.entities);

答案 2 :(得分:1)

你错误拼写选择:

SELECT * FROM entities.entities     WHERE entities.entities.id =         ( SELECT MAX(entities.entities.id)FROM entities.entities);

答案 3 :(得分:1)

是的,请务必先检查您的代码。

SELECT * FROM entities.entities
WHERE entities.entities.id =         
(SELECT MAX(entities.entities.id) FROM entities.entities); 

SELET - >的选择

此致