Skip to content

Instantly share code, notes, and snippets.

@vincentdesmares
Created May 12, 2017 00:21
Show Gist options
  • Save vincentdesmares/dd8fa788e958da3b559acbd3c7ab12ec to your computer and use it in GitHub Desktop.
Save vincentdesmares/dd8fa788e958da3b559acbd3c7ab12ec to your computer and use it in GitHub Desktop.
SELECT *
FROM
(
(SELECT *
FROM employe
WHERE category = 'A'
ORDER BY salary DESC
LIMIT 2)
UNION (SELECT *
FROM employe
WHERE category = 'B'
ORDER BY salary DESC
LIMIT 2)
UNION (SELECT *
FROM employe
WHERE category = 'C'
ORDER BY salary DESC
LIMIT 2)
UNION (SELECT *
FROM employe
WHERE category = 'D'
ORDER BY salary DESC
LIMIT 2)
UNION (SELECT *
FROM employe
WHERE category = 'E'
ORDER BY salary DESC
LIMIT 2)
) AS tmp
ORDER BY category, salary DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment