SELECT price * qty AS total FROM items ORDER BY total DESC; works in PostgreSQL. What is total referring to?
Correct answer
D. The output column alias, which ORDER BY accepts even though WHERE does not
17 views
D. The output column alias, which ORDER BY accepts even though WHERE does not
17 views
ORDER BY is logically evaluated after SELECT, so it can see output aliases, while WHERE runs before and cannot. Standard SQL also allows an integer position in ORDER BY, which is convenient but fragile when the select list changes. The alias must be double-quoted, or written in lowercase, to survive the folding rules of the database.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is D? Ask here and get an explanation.