What will be the output of the following query if the table dept has duplicate…
2023
What will be the output of the following query if the table dept has duplicate department names?
SELECT DISTINCT dept_name
FROM dept
ORDER BY dept_name DESC NULLS FIRST;
- A.
All department names with duplicates removed, but order is random
- B.
All unique department names sorted descending, NULLS first
- C.
Same as GROUP BY dept_name
- D.
All department names sorted ascending, NULLS at bottom
Attempted by 169 students.
Show answer & explanation
Correct answer: B
The correct answer is Option B: All unique department names sorted descending, NULLS first. The DISTINCT keyword eliminates duplicate rows from the output. The ORDER BY dept_name DESC NULLS FIRST clause explicitly sorts these unique department names in descending alphabetical order while positioning any NULL values at the very top of the result set.