Showing posts with label Sql Tutorial. Show all posts
Showing posts with label Sql Tutorial. Show all posts

Monday, April 11, 2011

How to Avoid Duplicate Values In Sql

SQL SELECT DISTINCT Statement will allows you to avoid Duplicate Values while fetching data from database.

SELECT DISTINCT column_name FROM table_name

The "Persons" table:

P_Id City

1 Sandnes

2 Sandnes

3 Stavanger

Now we want to select only the persons living in the city "Sandnes" from the table above.

We use the following SELECT statement:SELECT * FROM Persons

WHERE City='Sandnes'

The result-set will look like this:

P_Id City

1 Sandnes

2 Sandnes