Tuesday 13 January 2015

Preventing Duplicates with DISTINCT in SQL

By default, a SELECT statement returns result of a query without eliminating duplicate records. For instance, if you execute select job_id from employees, you will get all records including some duplicate entries in the job_id column. In order to fetch unique job ids, you will have to use the DISTINCT clause just after the SELECT keyword, as shown in the following example.


    SQL Statement :

SELECT      distinct job_id
FROM         employees;

    Output :


















No comments:

Post a Comment