Select DISTINCT records by SQL queries: If we need to select only the distinct values for any column, then we can use DISTINCT keyword along with SELECT in SQL Queries. Hence, we can say that DISTINCT allows to retrieve unique rows from a table. We can also say that to delete duplicate rows from the final result set we can use this keyword. With use of SELECT DISTINCT in SQL Query, we are just removing the duplicate records from the final output and not from the table. We will see later how to delete duplicate records from the table. Below is the query format to fetch DISTINCT rows from table:

SELECT DISTINCT columns FROM table;

Using the above structure, we can fetch distinct Cust_Operator from customers table.

SELECT DISTINCT Cust_Operator FROM customers ;

SELECT DISTINCT records by SQL queriesSELECT DISTINCT applies to all the columns added in SELECT clause and not only to the first column. Look at the below query format:

SELECT DISTINCT column1,column2 FROM table;

In this case, it will return the distinct rows for the combination of column1 and column2 and not only on the basis of column1.
To view the original result set click here.

Leave a Reply

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