小编典典

MySQL中的UNION和ORDER BY问题

sql

您应该在这里看到我正在尝试执行的操作,但是它不起作用

$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”。


阅读 259

收藏
2021-03-08

共1个答案

小编典典

尝试:

$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)";

查阅精美的手册

2021-03-08