Solution
SELECT *
FROM nobel_win
WHERE year=1970
ORDER BY
CASE
WHEN subject IN ('Economics','Chemistry') THEN 1
ELSE 0
END ASC,
subject,
winner;
SQL Basic Select Statement: Exercise-23 with Solution.
In this solution, year
is in front of DESC
. I'm confused. Does the order of ASC
,DESC
and the column title matter? Like the one in exercise 24, both subject
and winner
are put after ASC
. Are they both in ascending order?
CodePudding user response:
In SQL to order the result in ascending or descending, we have to put ASC or DESC keyword after the column name that we need to sort. For example, in Exercise 24 the ASC keyword is after the order by statement. This means the result is in ascending order according to your case.
In exercise 23 the DESC keyword is after the year. This means the result is ordered in descending order considering the year column.
So as a conclusion the keywords ASC and DESC are used after the field name that we want to arrange in order.
Check this link for more details about orders by ASC and DESC.