List Unique Customer CitiesEasy

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