Practice · Demographics · Medium
Return the 5 governorates with the longest names: name and its LENGTH as len, longest first (ties by name).
Runs in your browser. No signup needed.
Use the LENGTH(name) function.
SELECT name, LENGTH(name) AS len
FROM governorates
ORDER BY len DESC, name
LIMIT 5;
The reference solution is checked automatically when you run your query on the practice page — results are compared row by row, and order matters for this one.
String functions like LENGTH, UPPER, LOWER, SUBSTR and TRIM are everyday tools for cleaning messy text data. (SQLite docs)