Given the table Employees with columns id, name, and salary, what will be the order of name after running this query?
SELECT name FROM Employees ORDER BY salary ASC;
CREATE TABLE Employees (id INT, name VARCHAR(20), salary INT); INSERT INTO Employees VALUES (1, 'Alice', 5000), (2, 'Bob', 3000), (3, 'Charlie', 4000);
ORDER BY salary ASC sorts salaries from smallest to largest.
The query orders employees by their salary in ascending order. Bob has the lowest salary (3000), then Charlie (4000), then Alice (5000).
Identify the query that will cause a syntax error when ordering by a single column.
ORDER BY must be followed by a column name or expression.
Option A ends ORDER BY without specifying a column, causing a syntax error.
Assuming Orders table has an index on order_date, which query will best use the index to order results?
Ordering by the indexed column directly is faster than using functions on it.
Ordering by order_date ASC uses the index efficiently. Using functions like YEAR() or arithmetic disables index usage.
Given this query:
SELECT product_name FROM Products ORDER BY price;
Prices are stored as VARCHAR, not numeric. What is the cause of unexpected order?
Think about how strings are sorted compared to numbers.
VARCHAR columns sort lexicographically, so '100' is less than '20' because '1' < '2'.
Consider a table Customers with 1000 rows. What does ORDER BY last_name do when used without LIMIT?
ORDER BY affects the order of all rows returned.
ORDER BY sorts the entire result set. Without LIMIT, all rows are returned sorted.