Sql select unique

This article is tagged with: Sql select unique and mysql

sql select unique

SELECT DISTINCT column1, column2, ...
FROM table_name;

sql unique

-- To name a UNIQUE constraint, and to define a UNIQUE constraint on
-- multiple columns, use the following SQL syntax:
-- MySQL / SQL Server / Oracle / MS Access:
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
CONSTRAINT UC_Person UNIQUE (ID,LastName)
);

DISTINCT SQL

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

sql server select rows by distinct column

SELECT a.*
FROM emails a
INNER JOIN
(SELECT email,
MIN(id) as id
FROM emails
GROUP BY email
) AS b
ON a.email = b.email
AND a.id = b.id;

query DISTINCT

SELECT DISTINCT Column_name FROM table_name;

This article is tagged with: Sql select unique and mysql