-- You can select all the unique values from a column using the DISTINCT keyword:
SELECT DISTINCT example_column
FROM example_table;
SELECT
DISTINCT country
FROM City;
DISTINCT
- select distinct * from employees; ==>
retrieves any row if it has at
least a single unique column.
- select distinct first_name from employees; ==>
retrieves unique names
from table. (removes duplicates)
- select distinct count(*) from employees;
retrieve number of unique rows
if any row has at least a single unique data.
DISTINCT
- select distinct * from employees; ==>
retrieves any row if it has at
least a single unique column.
- select distinct first_name from employees; ==>
retrieves unique names
from table. (removes duplicates)
- select distinct count(*) from employees;
retrieve number of unique rows
if any row has at least a single unique data.
CREATE TABLE Persons (
ID int NOT NULL UNIQUE,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);
SELECT DISTINCT col1, col2, ....
FROM table_name;
SELECT col1, MIN(col2)
FROM table_name
GROUP BY col1;
DISTINCT
- select distinct * from employees; ==> retrieves any row if it has at
least a single unique column.
- select distinct first_name from employees; ==> retrieves unique names
from table. (removes duplicates)
- select distinct count(*) from employees; retrieve number of unique rows
if any row has at least a single unique data.