Differences between UNIQUE and DISTINCT in select statements
Answers were Sorted based on User's Feedback
Answer / rob reid
Howard Cheon is correct. They are THE SAME. There is no
The following is from the Oracle 9i SQL Reference (Note the
statement "these two keywords are synonymous" - that means
they mean the same thing):
DISTINCT | UNIQUE
Specify DISTINCT or UNIQUE if you want Oracle 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.
Restrictions on DISTINCT and UNIQUE Queries
When you specify DISTINCT or UNIQUE, the total number of
bytes in all select list expressions is limited to the size
of a data block minus some overhead. This size is specified
by the initialization parameter DB_BLOCK_SIZE.
You cannot specify DISTINCT if the select_list contains LOB
|Is This Answer Correct ?||59 Yes||6 No|
Answer / manoj
UNIQUE(Constraint):- Can be only once for a column in a
DISTINCT(Clause):- Useed in select query to retrive distinct
(non repeated) data from table(s)
|Is This Answer Correct ?||114 Yes||68 No|
the diff between unique and distinct is
unique is applied before insertion and retrival.it consists
of non duplicate values.if unique constraint is given it
does not take duplicate values.distinct is used in retrival
it gives the suppressed row(ex if two rows are same it will
show single row and non duplicate row) therefore distinct is
the combination of suppressed duplicate and non duplicate rows.
|Is This Answer Correct ?||35 Yes||11 No|
Answer / gourvendra singh
Buddy i dont found any difference in using distinct and
unique in the select statement, as both are performing same
operation in the select statement, almost every diff you
have discussed i want to add one that is u cant use
distinct in the create whereas unique u can.
|Is This Answer Correct ?||19 Yes||9 No|
Answer / manoj
see cautiously the major difference b/w unique and
UNIQUE :Allways take part on DATA INSERTION (In brief)
DINTINCT:Allways concern on data retrival (In brief)
Now we will take following case
case 1: UNIQUE KEY is defined (may b 4 one or more column)
It means this constraint will not allow us to
INSERT duplicate record/column_value(s)(i.e. exactly
same record/column_value(s) again for specified key column
NOW if u use DISTINCT clause in query
(select DISTINCT.from.)the will b same as simple query
Bcoz data are already not repeated (bcoz of constraint)
case 2:if UNIQUE not defined
data may b repeated and DISTINCT will now useful
Have eye on Major difference
(and we never use UNIQUE CONS.. in select.....)
|Is This Answer Correct ?||40 Yes||31 No|
Answer / cutepa1
yeah Manoj, this was analysed with your previous answer
itself but please try these statements and help me with
it's significance on the statements.
select unique(<clomun_name>) from <table_name>;
select distinct(<clomun_name>) from <table_name>;
|Is This Answer Correct ?||16 Yes||8 No|
Answer / gvmahesh
unique is a constraint it's declare for preventing the data
duplication.we create it along with table creation.
DISTINCT is a clause it is used for retrieving the data
without duplication.but it can't prevent the data
duplication.It just hiding the duplicated data.
|Is This Answer Correct ?||11 Yes||3 No|
Answer / karthicksharma
As said earlier UNIQUE is a constraint and can be used
during a table creation to prevent duplication of data .
CREATING A TABLE USING UNIQUE CONSTRAINT:
SQL> create table empl1 (name varchar2(15),no number(5)
So from this it is clearly implied that UNIQUE constraint
is used to prevent INSERTION AS WELL AS RETRIVAL of non-
whereas DISTINCT clause can only be used for RETRIVAL of
Whereas DISTINCT is a clause and cannot be used during a
table creation to limit the duplication of data.
CREATING A TABLE USING DISTINCT CLAUSE:
create table empl2(name varchar2(15),no number(5) distinct)
ERROR at line 1:
ORA-00907: missing right parenthesis
|Is This Answer Correct ?||7 Yes||0 No|
Answer / david alexander
There is some confusion here. Yes, UNIQUE is a constraint,
but the question is not about constraints, its about a
select statement. And, to answer it quite simply, its a
trick question. There is no difference. Although I always
see it as DISTINCT. Here is the quote from Oracle® Database
SQL Reference 10g Release 2 (10.2):
"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
|Is This Answer Correct ?||8 Yes||4 No|
Answer / qman*
The two keywords are only synonymous in regards to a SELECT
statement, and also ONLY in an Oracle environment. DISTINCT
is an ANSI standard where as UNIQUE can only be used this
way in Oracle. To further the differences between the two,
UNIQUE may also be used in a table creation statement to
specify that inputs into the specified column cannot share
the same value, and if attempted will result in a
constraint violation error, I hope this clears things up.
|Is This Answer Correct ?||5 Yes||1 No|
If a View on a single base table is manipulated will the changes be reflected on the base table?
write a query to delete similar records in different tables with same structure
what is julian date in oracle
IN A TABLE HAVE ONE COLUMN PRIMARY KEY..IT WILL NOT ALLOWS NULL VALUES AND DUPLICATE VALUES..INSTEAD OF PRIMARY KEY WHY CANT WE USE UNIQUE AND NOT NULL.THESE TWO ALSO DOESNT ACCEPT NULL VALUES IN NOT NULL AND UNIQUE DOESNT ACCEPT DUPLICATE VALUES? SO WHAT IS THE DIFEERENCE BETWEEN(UNIQUE,NOT NULL) AND PRIMARY KEY??????
What is a null value?
In a package if we have 10 procedures or functions,How to know which will execute first?
What is case function?
what is a relationship and what are they? : Sql dba
What are the usage of SAVEPOINTS?
What does inner join mean?
What is crud stand for?
Why stored procedure is faster than query?