MySQL中的UNION和ORDER BY问题

你应该看看我在这里想做什么,但它没有用

$getquery = "SELECT * 
FROM highscore 
WHERE score >= '$score'
ORDER BY score ASC
LIMIT 6

UNION

SELECT * 
FROM highscore 
WHERE score < '$score'
ORDER BY score DESC
LIMIT 5";

mysql_error()返回:“ORDER BY和UNION的使用不当”.

最佳答案
尝试:

$getquery = "(SELECT * 
FROM highscore 
WHERE score >= '$score'
ORDER BY score ASC
LIMIT 6)

UNION ALL -- guaranteed to be beneficial in this case as Johan commented

(SELECT * 
FROM highscore 
WHERE score < '$score'
ORDER BY score DESC
LIMIT 5)";

comments to my answer on the related question.
consult the fine manual.

转载注明原文:MySQL中的UNION和ORDER BY问题 - 代码日志