I have this query (simplified):
SELECT score FROM tbl WHERE id = xx ORDER BY score DESC;
And it works correctly. Now I add to this query an UNION like this:
(SELECT score FROM tbl WHERE id = x ORDER BY score DESC)
UNION
(SELECT score FROM tbl WHERE id = y)
Now all the first result-set of the first query is messed up not respecting the ORDER BY score DESC
SELECT score FROM tbl WHERE id = x
UNION
SELECT score FROM tbl WHERE id = y
ORDER BY score DESC;
just add the order by to the end. it will apply to the entire result set. If you want to differentiate the result add an order col like so:
SELECT 1 as order_col, score FROM tbl WHERE id = x
UNION
SELECT 2 as order_col, score FROM tbl WHERE id = y
ORDER BY order_col ,score DESC;