How to ORDER inside a CASE

In the case of this code - from the Querries part of learnin SQL:

SELECT name, 
  WHEN genre ='romance' OR genre = 'comedy' THEN 'Chill'
  ELSE 'Intense'
 END AS 'Review'
FROM movies;

How could I order the resulting list by the new categories (intense, chill etc.)?


@lorenzosauer94139594, welcome to the forums!

You can order by your new column just like you would any other column.

Ok, got it, by using the give name right?
Like adding


To order it by just which mood (it looks like you called the column Review instead of Mood), you would say ORDER BY Review. This would give you all the movies that are marked Chill, and then all the ones that are marked Intense.

If you want to further order those by their name, you would say ORDER BY Review, name

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.