User Display Names
Build a display name for every user in users:
1. If both first_name and last_name are present, use first_name || ' ' || last_name.
2. Otherwise, if username is present, use username.
3. Otherwise use 'user-' followed by the user_id (for example user-42).
Missing values are stored as NULL.
Return columns user_id, display_name. Row order does not matter.
Schema
CREATE TABLE users ( user_id INTEGER PRIMARY KEY, first_name TEXT, last_name TEXT, username TEXT );
Sample data
users
| user_id | first_name | last_name | username |
|---|---|---|---|
| 1 | Hiba | Khalil | hibak |
| 2 | Ian | NULL | ian_dev |
| 3 | NULL | NULL | quietfox |
| 4 | NULL | NULL | NULL |
| 5 | Jade | Okafor | NULL |
Hint 1
In SQLite, concatenating anything with NULL using || gives NULL.
Hint 2
COALESCE returns its first non-NULL argument.
Good practice for: Backend Developer, Full Stack Developer, Data Analyst
SQL (SQLite)
Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.