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
Does mysql_real_escape_string prevent sql injection?
How do I view an execution plan in sql?
What is union?
How many parts of a pl sql block are optional?
Do we need to rebuild index after truncate?
What are the sql aggregate functions?
What is the purpose of the partition table?
What is pl sql script?
What is a schema sql?
What are the different operators available in sql?
what are different types of keys in sql?
How to sort the rows in sql.
What is union and union all keyword in sql and what are their differences?
How to change a value of the field ‘salary’ as 7500 for an employee_name ‘john’ in a table employee_details?
What is the difference between the sql*loader and import utilities? : aql loader