Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Tuesday, April 16, 2013

6 : SQL " SELECT DISTINCT " STATEMENT


In a table, some of the columns may contain duplicate values. This is not a problem, however, sometimes you will want to list only the different (distinct) values in a table.

The DISTINCT keyword can be used to return only distinct (different) values.

The created Table is : 


Create a Database named "Studysql" and a table named "tbl_biodata"
Right click on the database Studysql and select new query.Then we can write queries as per the requirements.
( Click here to know how created this table )

ID
NAME
AGE
CITY
PHONE
1
Priyada
25
Cochin
1000000001
2
Mohan
30
Cochin
2000000002
3
Jaimon Jacob
40
Vytila
3000000003
4
Sumith
24
Kottayam
4000000004
5
Shaiju
36
Thrissur
5000000005


Here, refer the field CITY . The column COCHIN is repeated 2 times.

Now we want to select only the distinct values from the column named "City" from the table above.

To do so, write the command like this in SQL.

SELECT DISTINCT City FROM tbl_biodata


The result-set will look like this:


SQL SELECT Syntax of the same is : 


SELECT DISTINCT column_name(s)
FROM table_name




No comments: