sql unique value code example

Example 1: DISTINCT SQL

SELECT DISTINCT column1, column1, ..... FROM TABLE
/*DISTINCT WILL NOT SELECT THE SAME VALUES IN SAME COLUMN*/

Example 2: sql unique

This constraint ensures all values in a column are unique.
Example 1 (MySQL): Adds a unique constraint to the id column when
creating a new users table.
CREATE TABLE users (
id int NOT NULL,
name varchar(255) NOT NULL,
UNIQUE (id)
);
Example 2 (MySQL): Alters an existing column to add a UNIQUE
constraint.
ALTER TABLE users
ADD UNIQUE (id);

Example 3: sql distinct

#List unique values in the df['name'] column
df.name.unique()