Sorting and Limiting Results Flashcards
7 cards from real SQL practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Sorting and Limiting Results flashcards as text
Can you use a column alias defined in SELECT inside ORDER BY?
Answer: Yes, in most databases
ORDER BY runs after SELECT, so column aliases are usable there.
Which query finds the top 3 highest-priced products?
Answer: ORDER BY price DESC LIMIT 3
Sorting price descending and limiting to 3 returns the most expensive items.
What is the risk of using LIMIT/OFFSET for pagination on large tables?
Answer: Large offsets get slower as they scan and skip rows
High OFFSET values force the database to scan and discard many rows, hurting performance.
Which expression sorts case-insensitively in many databases?
Answer: ORDER BY LOWER(name)
Applying LOWER() to the column normalizes case before sorting.
Can ORDER BY use an expression like ORDER BY price * quantity?
Answer: Yes, expressions are allowed
ORDER BY accepts arbitrary expressions, not just plain columns.
In SQL Server, how do you get the top 10 percent of rows?
Answer: SELECT TOP 10 PERCENT
SQL Server supports TOP n PERCENT to return a percentage of rows.
Which clause combination is required for reliable pagination?
Answer: ORDER BY with LIMIT/OFFSET
Without ORDER BY, pagination results can vary between queries.