Created
October 11, 2011 09:43
-
-
Save leevigraham/1277716 to your computer and use it in GitHub Desktop.
Select top 5 entries grouped by category
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 * | |
FROM | |
( | |
SELECT cp.cat_id, cp.entry_id, ct.title, | |
@num := if(@group = cp.cat_id, @num + 1, 1) as row_number, | |
@group := cp.cat_id as group_key | |
FROM (SELECT @group:=null,@num:=0) n | |
CROSS JOIN exp_category_posts cp | |
LEFT JOIN exp_channel_titles ct on cp.entry_id = ct.entry_id | |
ORDER BY cp.cat_id | |
) temp_table | |
WHERE row_number <= 5; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment