DISTINCT clause in Oracle. How it differs from UNIQUE clause?

Basically for all new Oracle SQL learning people it is quite necessary to get knowledge on DISTINCT clause. As experienced persons are very much well-versed with DISTINCT clause they can skip this article and relax in their arm chair for time being (though there are many interesting articles you can go through in OracleMine).

DISTINCT Clause

Simple use of DISTINCT clause is to retrieve only single set of duplicate records if used in SQL statement. SELECT clause retrieves total number of rows when run. Using DISTINCT clause will restrict duplicate records and instead show only one copy of it.

Syntax

Example

DISTINCT clause can also be used with multiple fields to return unique combination of those columns.

Example

How does DISTINCT clause differs from UNIQUE clause?

DISTINCT and UNIQUE clause are similar to each other. Only difference is UNIQUE clause is proprietary of Oracle while DISTINCT clause is an SQL standard. For other databases like MySQL, MSSQL etc. UNIQUE clause is not identifiable.

In general practice we use DISTINCT clause instead of UNIQUE clause.

Syntax of UNIQUE clause

Example

If you liked the above post, please leave your comments.

You can also Subscribe here to stay updated on latest posts of OracleMine.com.

I am the owner of OracleMine.com. I believe you should never quit in life if you want to achieve something. Just work hard, leave it all on supreme power to deliver the results. I like blogging and writing very much. In my past time, I like to read books too, especially fictional novels.

Leave a Reply

Your email address will not be published. Required fields are marked *