0

Hi everyone,

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

Thanks,

Nick

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by stupidenator
0

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
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.