Wednesday, October 15, 2014

ELIMINATING DUPLICATE ROWS WHEN USING A SELECT STATEMENT



A table could hold duplicate rows. In such a case, to view only unique rows the distinct clause can be used.

The DISTINCT clause allows removing duplicates from the result set. The DISTINCT clause can only be used with select statements.

The DISTINCT clause scans through the values of the column/s specified and displays only unique values from amongst them.

SELECT DISTINCT , FROM ;

The SELECT DISTINCT * SQL syntax scans through entire rows, and eliminates rows that have exactly the same contents in each column.

SELECT DISTINCT * FROM ;
Example:
Show different types of occupations of the customers by eliminating the repeated occupations
SELECT DISTINCT OCCUP FROM CUST_MSTR;
Output:
OCCUP
‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑­
Business
Community Welfare
Executive
Information Technology
Retail Business
Self Employed
Service

7 rows selected.

No comments: