Created
April 4, 2015 16:51
-
-
Save pomek/c7d899274def736175f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
DISTINCT w.name, | |
w.categoryId, | |
c.name as category | |
FROM | |
work w | |
JOIN | |
category c | |
ON | |
c.id = w.categoryId | |
INNER JOIN | |
( | |
SELECT | |
GROUP_CONCAT | |
(w.id ORDER BY w.id DESC) grouped | |
FROM | |
work w | |
GROUP BY | |
categoryId | |
ORDER BY | |
w.id ASC | |
) AS works | |
WHERE | |
FIND_IN_SET(w.id, works.grouped ) BETWEEN 1 AND ? | |
ORDER BY | |
categoryId ASC, | |
w.id DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment