Back to Practice
#0312
Sort Products by Price Then Name
EasySQL15 min10 XP
Problem
Return product and price ordered by price descending, then product ascending.
Why This Matters
SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.
Schema
products(product TEXT, price INTEGER)
Examples
Example 1
Inputproducts with tied prices
Outputhighest price first, ties alphabetical
The second ORDER BY key makes tied prices deterministic.
Constraints
- Return only the requested columns.
- Use deterministic ORDER BY when multiple rows are returned.
- Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Inputproducts with tied prices
Expected[["Monitor",150],["Keyboard",50],["Cable",25],["Mouse",25]]
The second ORDER BY key makes tied prices deterministic.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks