List unique customer cities

Return one city column containing each distinct non-NULL city in customers. Keep an empty string if it exists. Row order does not matter.

Difficulty: beginner

Show hint

Use DISTINCT and IS NOT NULL. NULL and an empty string are different values.

Tables and sample data

Each test starts with fresh tables. Result rows may be returned in any order. Column names and column order must match.

Sample data: customers
customer_id (integer)name (text)city (text)
1AshaKathmandu
2BinaPokhara
3ChenKathmandu
4DeeNULL
Expected sample result
city
Kathmandu
Pokhara

Your solution

SQL · PostgreSQL

Results

PostgreSQL loads when you Run or Submit. Write one read-only SELECT or WITH query. Your query runs in this browser.

Back to Lesson