| | |
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 |
|
|
Here again the DISTINCT command in SQL
SELECT DISTINCT class FROM 'student'
The output is displayed here
As you can see only two rows are returned and they are the distinct class in the
table
| | kashif | 05-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 Kaushal | 18-03-2009 |
|---|
| Thank u very much | | Kamran | 13-07-2009 |
|---|
| i want to learn sql, i am the new joiner, so please if have you any basic | | Alok Patoria | 21-01-2010 |
|---|
| i found dis helpfull.bt dere should be some heierarchy for the topics. |
|
|
|
|
|
|