2013-10-02 39 views
2

我使用我的MySQL數據庫這一行:SQL USE INDEX語法錯誤

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

我想不通爲什麼,但數據庫返回以下錯誤:

[Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'time_desc WHERE nodeId =10048 AND time <=1377040709 AND valid =1 ORDER BY `ti' at line 1]

任何想法,因爲我該如何解決這個問題?

+0

http://dev.mysql.com/doc/refman/5.1/en/index-hints.html你需要在'parens'(time_desc)中附上'time_desc'' –

回答

2

您需要括號圍繞索引名

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

揍我吧! :) +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