List Unique Customer Cities
EasySQLPractice library · +10 XPdistinct valuessqlcustomers
A retail company wants to understand the geographic distribution of its customers. They need a list of all the unique cities where their customers reside.
Tables:
Customers(CustomerID, FirstName, LastName, City, Country)
Return the distinct cities.
The order of the output does not matter.
Tables
CREATE TABLE Customers (
CustomerID integer PRIMARY KEY,
FirstName varchar(50) NOT NULL,
LastName varchar(50) NOT NULL,
City varchar(100),
Country varchar(50)
);Example data
INSERT INTO Customers (CustomerID, FirstName, LastName, City, Country) VALUES (1, 'Amit', 'Sharma', 'New Delhi', 'India'), (2, 'Priya', 'Singh', 'Mumbai', 'India'), (3, 'Rahul', 'Verma', 'New Delhi', 'India'), (4, 'Sneha', 'Patel', 'Ahmedabad', 'India'), (5, 'Vikram', 'Rao', 'Mumbai', 'India'), (6, 'Anjali', 'Gupta', 'Bangalore', 'India'), (7, 'Rohit', 'Mehta', 'New Delhi', 'India');
Your query is also checked on hidden datasets with different data.
Hints
-- Select the distinct cities from the Customers table
SELECT
Your query runs on the example tables shown with the problem, then on hidden datasets when you submit.
Write standard SQL. MySQL habits work too: IFNULL, IF, YEAR(), DATE_FORMAT, GROUP_CONCAT, `backticks` and LIMIT 5, 10. It runs on PostgreSQL, so integer division keeps whole numbers (5 / 2 = 2): write 5.0 / 2 for 2.5.