Tuesday, 13 January 2015

Using Multiple Distinct Columns in SQL

In the previous example, you used just one column (JOB_ID) to display unique values. DISTINCT can also be applied to all the columns in a SELECT statement. With DISTINCT applied to multiple columns, the returned dataset displays distinct combination of the selected columns as shown in the following example, which shows all the different combinations of FIRST_NAME and JOB_ID. Since there are no two employees with the same first name and the same job id, the query fetches all rows from the table. If, for instance, there were two employees having Alexander as their first name enrolled under the job id IT_PROG, the result would have shown just one record.


    SQL Statement :

SELECT      distinct first_name, job_id
FROM         employees;

    Output :






No comments:

Post a Comment