Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between SELECT DISTINCT and SELECT UNIQUE [duplicate]

Tags:

oracle

Possible Duplicate:
Unique vs distinct multi-column in Oracle 9i

Proper difference between SELECT DISTINCT and SELECT UNIQUE with points and examples.

like image 236
Pinaki Avatar asked Jul 21 '11 07:07

Pinaki


People also ask

What is the difference between SELECT distinct and SELECT unique?

The UNIQUE keyword in SQL plays the role of a database constraint; it ensures there are no duplicate values stored in a particular column or a set of columns. On the other hand, the DISTINCT keyword is used in the SELECT statement to fetch distinct rows from a table.

What's the difference between distinct and unique?

The main difference between unique and distinct is that UNIQUE is a constraint that is used on the input of data and ensures data integrity. While DISTINCT keyword is used when we want to query our results or in other words, output the data.

What is the difference between distinct values and unique values?

“Distinct” means total number of different values regardless how many times it appears in the dataset. A name appears in the list multiple times is counted as 1 distinct count. Whereas, the “Unique” value is total number of values that only appear once.

What is unique and unique all in SQL?

The UNIQUE constraint ensures that all values in a column are different. Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE constraint.


2 Answers

SELECT DISTINCT and SELECT UNIQUE behave the same way in oracle.

While DISTINCT is ANSI SQL standard, UNIQUE is an Oracle specific statement.

Look here: http://psoug.org/definition/DISTINCT.htm

like image 135
powerMicha Avatar answered Sep 17 '22 13:09

powerMicha


Oracle official documentation

http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_10002.htm#sthref9346

States that:

DISTINCT | UNIQUE

Specify DISTINCT or UNIQUE if you want the database to return only one copy of each set of duplicate rows selected. These two keywords are synonymous. Duplicate rows are those with matching values for each expression in the select list.

like image 37
Edgar Velasquez Lim Avatar answered Sep 19 '22 13:09

Edgar Velasquez Lim