Skip to content Skip to sidebar Skip to footer

Union And Order By Issue In Mysql

You should see what I'm trying to do here but it's not working $getquery = 'SELECT * FROM highscore WHERE score >= '$score' ORDER BY score ASC LIMIT 6 UNION SELECT * FROM h

Solution 1:

Try:

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

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

Solution 2:

To apply ORDER BY or LIMIT to an individual SELECT, place the clause inside the parentheses that enclose the SELECT:

(SELECT*FROM highscore 
 WHERE score >='$score'ORDERBY score ASC
 LIMIT 6)

UNION

(SELECT*FROM highscore 
 WHERE score <'$score'ORDERBY score DESC
 LIMIT 5)

Post a Comment for "Union And Order By Issue In Mysql"