snoodle
05-06-2009, 05:37 PM
My SQL is not so hot...
Consider the simple table, "test", which has 2 columns, "type" and "name".
TYPE - NAME
fruit - cherry
fruit - apple
fruit - banana
dog - terrier
dog - poodle
I would like to group by type, and order by type, then name (actually, I'd like to pick out the 1st item of each group (first, according to my secondary order col).
SELECT * FROM `test` GROUP BY type order by type ASC, name ASC
yields...
TYPE - NAME
dog - terrier
fruit - cherry
...when I expected...
TYPE - NAME
dog - poodle
fruit - apple
It appears to ignore the secondary order column.
I've had the same problem using distinct.
Consider the simple table, "test", which has 2 columns, "type" and "name".
TYPE - NAME
fruit - cherry
fruit - apple
fruit - banana
dog - terrier
dog - poodle
I would like to group by type, and order by type, then name (actually, I'd like to pick out the 1st item of each group (first, according to my secondary order col).
SELECT * FROM `test` GROUP BY type order by type ASC, name ASC
yields...
TYPE - NAME
dog - terrier
fruit - cherry
...when I expected...
TYPE - NAME
dog - poodle
fruit - apple
It appears to ignore the secondary order column.
I've had the same problem using distinct.