Tutorials

SQL SELECT


SQL SELECT DISTINCT


SELECT DISTINCT in sql helps to fetch distinct data from a coloumn.

 

Syntax for SELECT DISTINCT

SELECT DISTINCT column1, column2,..., columnN FROM table_name;

Example on SELECT DISTINCT

 

For demonstration we will use our 'tih_Courses' table.

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .Net Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla Online
004 Basics of Computer Shweta  Online
 

We will apply our query now to fetch distinct or unique Professor in tih_Courses table.

 


 

SELECT DISTINCT Professor FROM tih_Courses;

On executing the above query successfully, we get below result:

 

tih_Courses
Professor
Mukesh Tiwari
Rajneesh Shukla
Shweta 

Here we get only unique results. 

Rajneesh was present twice in the table but when you use DISTINCT on SELECT then duplicate values are filtered.

 

SELECT UNIQUE is similar to SELECT DISTINCT.

Using either of them will give same result.

SELECT UNIQUE is old statement which was later replaced by DISTINCT.

 



Please Share this page
Views : 53
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!