SQL USE INDEX语法错误

时间:2013-10-02 11:02:43

标签: mysql sql database syntax syntax-error

我在MySQL数据库中使用这一行:

SELECT * FROM `dump` USE INDEX `time_desc` WHERE (`nodeId`=10047 AND `time`<=1377040709 AND `valid`=1) ORDER BY `time` DESC LIMIT 1;

我无法弄清楚原因,但数据库返回以下错误:

  

[错误:ER_PARSE_ERROR:您的SQL语法中有错误;校验   与您的MySQL服务器版本对应的手册   在'time_desc WHERE nodeId = 10048 AND附近使用的语法   time&lt; = 1377040709 AND valid = 1在第1行的'ti'订购]

有关我如何解决这个问题的想法吗?

2 个答案:

答案 0 :(得分:2)

您需要围绕索引名称

的括号
SELECT * 
FROM `dump` USE INDEX (`time_desc`)
WHERE (`nodeId`=10047 AND `time`<=1377040709 AND `valid`=1) 
ORDER BY `time` DESC 
LIMIT 1;

答案 1 :(得分:0)

试试这样: -

SELECT * FROM `dump` USE INDEX (`time_desc`)    --Use paranthesis here
WHERE (`nodeId`=10047 AND `time`<=1377040709 AND `valid`=1) 
ORDER BY `time` DESC 
LIMIT 1;

选中reference