Hi everyone,

What is the difference between UNIQUE and DISTINCT? It seems that they do the same thing.

Thanks,

Nick

Hi everyone,

What is the difference between UNIQUE and DISTINCT? It seems that they do the same thing.

Thanks,

Nick

UNIQUE is a constraint applied to tables that ensures that all values in the given columns are unique. If you try to insert a existing value the you will get an error (along the lines of 'insert violates unique constraint').

The DISTINCT command is used to return one instance of each value, for example if you have a table of names

select * from names;

forename
--------
Joe
Rory
David
Lee
Joe
Andrew
Andrew
David


select distinct forename from names;

forename
--------
Joe
Rory
David
Lee
Andrew