How to Select Distinct Rows in SQL ?

Share

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:


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

SELECT DISTINCT gender FROM user_details; 

Output:

 

This post was last modified on July 4, 2022

Sandeep Verma

Published by
Sandeep Verma
Tags: How to Select Distinct rows in SQL ? query SELECT DISTINCT statement sql statement