Consider a table Employees with columns id and name:
id | name ---+------- 1 | Alice 2 | Bob 3 | Charlie 4 | Diana
What is the result of this query?
SELECT name FROM Employees ORDER BY id DESC;
SELECT name FROM Employees ORDER BY id DESC;
ORDER BY with DESC sorts from highest to lowest.
The query orders employees by id in descending order, so the names appear from the highest id (4) to the lowest (1).
Given the same Employees table, what does this query return?
SELECT name FROM Employees ORDER BY name ASC LIMIT 2;
SELECT name FROM Employees ORDER BY name ASC LIMIT 2;
ORDER BY name ASC sorts names alphabetically from A to Z.
The query orders names alphabetically ascending and returns only the first two rows.
Which SQL query orders the Employees table first by name ascending, then by id descending?
Ordering columns are listed in the order of priority.
The correct syntax orders by name ascending first, then id descending.
Consider this query:
SELECT department, COUNT(*) FROM Employees GROUP BY department ORDER BY COUNT(*) DESC;
Why is the ORDER BY clause important here?
Think about what ordering by an aggregate function does.
ORDER BY COUNT(*) DESC sorts the grouped results so departments with more employees appear first.
Given the Employees table, what error does this query produce?
SELECT name FROM Employees ORDER BY salary;
Assume the salary column does not exist in the table.
SELECT name FROM Employees ORDER BY salary;
Ordering by a non-existent column causes an error.
The database raises a runtime error because the salary column is not found.