How to Select Distinct Rows in SQL ?

The SELECT DISTINCT statement would let you get only unique information from a field that consists lots of duplicate data. In other words, a field that contains  lots of repeated values, to ignore those repeated values the SELECT DISTINCT statement is used.

It won’t allow the column’s data to repeat more than a single time and it gives filtered information with optimization as it doesn’t fetch entire duplicate information (take less memory).

Syntax:

SELECT DISTINCT feild1,feild2,.. FROM  Table_name;

For Example:

Suppose you have a table namely as user_details:

distinct question


and if you want to fetch only non repeated value of gender field, the command would be:

SELECT DISTINCT gender FROM user_details; 

Output:

distinct

 

Leave a Reply