In a previous question I asked, someone suggested the MAX(value) syntax to prioritize on alphbetization
How to use GROUP BY to retrieve a result set with priority on alphabeticization
However I’m dealing with the CASE statement and using MAX(CASE statement) is syntactically incorrect.
SELECT id,
CASE
WHEN filename LIKE '%.mp3' THEN 'song'
ELSE 'other' END as type
FROM filenames
1 song
2 song
2 other
3 other
3 song
SELECT id,
CASE
WHEN filename LIKE '%.mp3' THEN 'song'
ELSE 'other' END as type
FROM filenames
GROUP BY id;
1 song
2 song
3 other
How would I prioritize the type field for those which come alphabetically last? Ex. the result set should be
1 song
2 song
3 song
I’d like to avoid nested statements if possible. Can this be done with the MAX(type) syntax?
You can use following
DESC will give you descending order