HI WELCOME TO KANSIRIS

The SQL SELECT DISTINCT Statement for deleting duplicate rows

Leave a Comment


The SELECT DISTINCT statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
The SELECT DISTINCT statement is used to return only distinct (different) values.

SELECT DISTINCT Syntax

SELECT DISTINCT column1, column2, ...
FROM table_name;

Demo Database

Below is a selection from the "Customers" table in the Northwind sample database:
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1
Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4
Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

SELECT Example

The following SQL statement selects all (and duplicate) values from the "Country" column in the "Customers" table:

Example

SELECT Country FROM Customers;
Now, let us use the DISTINCT keyword with the above SELECT statement and see the result.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.