1DISTINCT
2- select distinct * from employees; ==>
3 retrieves any row if it has at
4 least a single unique column.
5
6- select distinct first_name from employees; ==>
7 retrieves unique names
8 from table. (removes duplicates)
9
10- select distinct count(*) from employees;
11 retrieve number of unique rows
12 if any row has at least a single unique data.
1DISTINCT
2- select distinct * from employees; ==>
3 retrieves any row if it has at
4 least a single unique column.
5- select distinct first_name from employees; ==>
6 retrieves unique names
7 from table. (removes duplicates)
8- select distinct count(*) from employees;
9 retrieve number of unique rows
10 if any row has at least a single unique data.
1This constraint ensures all values in a column are unique.
2Example 1 (MySQL): Adds a unique constraint to the id column when
3creating a new users table.
4CREATE TABLE users (
5id int NOT NULL,
6name varchar(255) NOT NULL,
7UNIQUE (id)
8);
9Example 2 (MySQL): Alters an existing column to add a UNIQUE
10constraint.
11ALTER TABLE users
12ADD UNIQUE (id);