Concatenate First and Last Name for Premium Users
Show each premium user as a single full_name column, with email and city.
The challenge runs on the SQLabHub practice database (SQLite) and uses the users table. You can solve it in the browser, with nothing to install.
The task
List all premium users (is_premium = 1) showing their full name, email and city.
A correct answer returns 69 rows with 3 columns: full_name, email, city.
Tables used in this challenge
users 150 rows
id INTEGER (PK) · first_name TEXT · last_name TEXT · email TEXT · phone TEXT · city TEXT · country TEXT · created_at TEXT · status TEXT · is_premium INTEGER
| id | first_name | last_name | phone | city | country | created_at | status | is_premium | |
|---|---|---|---|---|---|---|---|---|---|
The first rows of each table are shown. See how all the tables relate on the database schema page.
Expected output
| full_name | city | |
|---|---|---|
First 5 of 69 rows. This is the output of the model solution on the practice database.
What you practise
- Filtering rows with a WHERE condition
- Building and cutting text values
- Sorting the result with ORDER BY
Hint and approach
Try the challenge first. Open these only when you need them.
Show the hint
Use WHERE is_premium = 1
Show the step-by-step approach
How the model solution is built, in the order the database evaluates it:
- Read from the
userstable. - Filter in
WHERE: keep the rows whereis_premiumequals 1. - Build
full_nameby joining text values with the||operator. - Sort the result by
last_name.
Model solution
Checking your session…
What to watch for
SQLite joins strings with the || operator; MySQL uses CONCAT() and SQL Server uses +. Remember the space literal between the two names, or they run together.
- String functions. In SQLite and PostgreSQL, joining text with || returns NULL as soon as one of the parts is NULL.
- ORDER BY. Without ORDER BY the row order is not guaranteed, even if it looks stable. Rows that tie on the sort columns can come back in any order.
- WHERE. WHERE is evaluated before the SELECT list, so it cannot use a column alias defined there or the result of an aggregate.
Related SQL challenges
- Sort Users by Signup Date, Newest FirstSimilar levelEasy
- Find the Top 15 Customers by Lifetime RevenueHarderMedium
- Segment Customers by Recency, Frequency and Monetary Value (RFM)HarderHard
Keep learning
- Lesson: String Functions
- Lesson: ORDER BY
- Lesson: WHERE Clause
- All SQL practice challenges, by difficulty and topic
- SQL interview questions with answers
- SQL Playground: run any query on the same database