Home SQL Basic SQL Distinct
09.09.2010
Main Menu
Programming
.NET Controls
Operating System
Databases
Articles
Add to: Digg Add to: Del.icoi.us Add to: Reddit Add to: StumbleUpon Add to: Slashdot Add to: Yahoo Add to: Technorati Add to: Google
SQL Distinct

When using the select statement there will be times when the return result will be duplicated. So how do we go about to retrieve only unique rows? The DISTINCT keyword can be used to retrieve the result with a unique rows.

SYNTAX:

SELECT DISTINCT "column_name" FROM "table_name"

EXAMPLES:

For example if we select all records from the Student table we would see the following 4 records:

SELECT LastName from Student;

Table: Student

StudentID LastName FirstName DOB
1 John Astone 07/15/1976
2 Bob Eastwood 02/13/1935
3 Jane Hollywood 03/23/1939
4 Bob Eastwood 03/19/1980

When using the DISTINCT keyword we would see the following result:

SELECT DISTINCT LastName from Student;

Result:

LastName
Bob
Jane
John




Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:angry::angry-red::evil::idea::love::x:no-comments::ooo::pirate::?::(
:sleep::););)):0
Security
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."