Differences between UNIQUE and DISTINCT in select statements
Answer Posted / 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:
=================================================
eg:
SQL> create table empl1 (name varchar2(15),no number(5)
unique);
Table created.
-----------------------------------------------------
So from this it is clearly implied that UNIQUE constraint
is used to prevent INSERTION AS WELL AS RETRIVAL of non-
duplicate data.
whereas DISTINCT clause can only be used for RETRIVAL of
non-duplicate data.
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:
===========================================
eg:
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 |
Post New Answer View All Answers
What is the basic form of sql query?
How many types of sql are there?
How do I truncate a word?
What is your daily office routine?
What is memory optimized table?
What are different functions in sql?
What is mdf ldf and ndf?
Is join same as left join?
How to rename a column in the output of sql query?
What is the difference between subquery and correlated query?
How delete a row in sql?
What is sql performance tuning?
Compare sql & pl/sql
What do you understand by case manipulation functions?
Is it possible to Restore a Dropped Table using Rollback Command in Oracle SQL Plus ?