一尘不染

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


阅读 233

收藏
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