Junior
What is the DISTINCT command and what is it used for?
sobes.tech AI
Answer from AI
The DISTINCT command in SQL is used to select only unique (non-repeating) values from a specified column or set of columns in the query results SELECT.
Usage:
- Removing duplicates in the result set.
- Getting a list of all unique values from a column (for example, a list of all different cities, customers, etc.).
Example of usage:
-- Select all unique cities from the "Customers" table
SELECT DISTINCT City
FROM Customers;
-- Select unique combinations of city and country from the "Customers" table
SELECT DISTINCT City, Country
FROM Customers;