I have a table that has columns for id,category and position:
id | cat | pos
--------------
01 | ct1 | 2
02 | ct1 | 3
03 | ct2 | 1
04 | ct1 | 1
05 | ct2 | 2
I want to select the rows with the lowest position from each category. So from this data I should get id's 03 and 04 since they are position 1 from each respective category.
I have seen similar posts but with slight twists that make it hard to translate the knowledge, for example one suggested solution only has two groups so they have a fixed UNION as the selected answer which is way off for me as categories can grow. A decent explanation would be nice as I do not understand why the following doesn't work.
SELECT id,pos,title,cat,des,url,urltext
FROM gallery_items
GROUP BY cat
ORDER BY pos ASC