SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

SQL DISTINCT Command


DISTINCT command in SQL collects the unique or distinct records from a field of a table. In the student table we are interested to know how many class records are there and the DISTINCT sql command should return class once only. So if class five is there ten times then it should return once and if class six one record is there then class six should return once.  

So using DISTINCT sql command we can avoid duplicate records in SELECT query



There is another related command sql group by which groups the data and brings the unique names. This group by command is usually used along with count, average, minimum, maximum commands. Here we will discuss sql distinct command only


DISTINCT command will return records once only.

SELECT DISTINCT class FROM student
This is our table and we will apply DISTINCT command to this table.
id name class mark
1 John Deo Four 75
2 Max Ruin Three 85
3 Arnold Three 55
4 Krish Star Four 60
5 John Mike Four 60
6 Alex John Four 55
Related Tutorial
Group by
SQL Maximum value
SQL Average
SQL Rename table
PHP MySQL functions
Here again the DISTINCT command in SQL

SELECT DISTINCT class FROM 'student'

The output is displayed here
class
Four
Three
As you can see only two rows are returned and they are the distinct class in the table


kashif05-01-2009
plus2net is gearttttt.....it is 1 of the best sites of da internet..i love this site for my problem solving n learning...plus2net is doing great job...best of luck....
Shaveen Kaushal18-03-2009
Thank u very much
Kamran13-07-2009
i want to learn sql, i am the new joiner, so please if have you any basic
Alok Patoria21-01-2010
i found dis helpfull.bt dere should be some heierarchy for the topics.
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked
Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
SQL Tutorial List
SQL Commands
SQL Sections
Date & Time
Join Table
String
Math
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.