Oracle Tutorial

What is Oracle
SQL Keywords

Oracle Wildcards

Oracle Wildcards

Oracle Aliases

Oracle Aliases

MySQL Tutorial

MySQL Tutorial

PL/SQL Tutorial

PL/SQL Tutorial

Oracle Interview Questions

Oracle Interview Questions and Answers


Oracle Distinct Clause

The Oracle DISTINCT clause is used to eliminate duplicate records from the table and retrieve only unique records. The Oracle DISTINCT clause is used with the SELECT statement only.

Note: In Oracle, the DISTINCT clause doesn't ignore NULL values.

Oracle DISTINCT CLAUSE Syntax

To retrieve only unique records from existing table, use the following syntax:

Syntax

SELECT DISTINCT col1,col2,col3... FROM tablename

Parameters:

tablename: The table name from which you want to remove all records.

DISTINCT: To eliminate duplicate records.

Note:

If DISTINCT clause is used with single field, the query will return the unique values for that field only.

If DISTINCT clause is used with multiple fields, the query will retrieve unique combinations for the expressions listed.

Oracle DISTINCT CLAUSE example with single field

The following Oracle statement to retrieve single field with unique records from "tblCustomer" table:

Example

SELECT DISTINCT address FROM tblCustomerLoan;

Note:

In the above example, we have fetched unique "address" from "tblCustomerLoan"

Show DISTINCT CLAUSE Example with NULL value

To retrieve unique records for NULL value, Oracle keeps one NULL value and eliminates the other because the DISTINCT clause treats all NULL values as the same value, use the following syntax:

Example

SELECT DISTINCT firstName FROM tblCustomerLoan;