Back to Practice
#0365
Most Common Country
MediumSQL24 min20 XP
Problem
Return the country with the most users. If tied, return the alphabetically first country.
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
users(user_id INTEGER, country TEXT)
Examples
Example 1
InputIndia and US both have 2 users
OutputIndia
The tie-breaker country ASC chooses India before US.
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
InputIndia and US both have 2 users
Expected[["India",2]]
The tie-breaker country ASC chooses India before US.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks