a
 
SQLRef.Com 

            SqlRef.Com


SQL BASIC
DATA QUERY LANGUAGE
BASIC FUNCTION
AGGREGATE FUNCTION
DATA MANIPULATION LANGUAGE
DATA DEFINITION LANGUAGE
DATA CONTROL LANGUAGE
OTHERS

DISTINCT

SELECT DISTINCT <column> FROM <table>

DISTINCT qualifier is used to remove duplicate rows from SELECT command.

Table: Orders
OrderID Customer Employee Order Date ShippedVia Freight ShipCountry
10248 Wilman Kala Buchanan, Steven 04-07-1996 Federal Shipping 32.38 France
10249 Hanari Carnes Peacock, Margaret 08-07-1996 United Package 65.83 Brazil
10250 Hanari Carnes Leverling, Janet 08-Jul-1996 United Package 58.17 Brazil
10251 Chop-suey Chinese Buchanan, Steven 11-Jul-1996 United Package 22.98 Switzerland
10252 Richter Supermarkt Dodsworth, Anne 12-Jul-1996 Federal Express 148.33 Switzerland

The following SQL statement will return ShipCountry for all records in Orders table as shown in Resultset1.

SELECT ShipCountry FROM Orders

Resultset1
ShipCountry
France
Brazil
Brazil
Switzerland
Switzerland

As you can see, Resultset1 contains duplicate rows. Brazil and Switzerland appear twice in the resultset1.

The following SQL statement will remove the duplicate rows with DISTINCT qualifier.

SELECT DISTINCT ShipCountry FROM Orders

Resultset2
ShipCountry
France
Brazil
Switzerland

Brazil and Switzerland only appear once in Resultset2.

.



 
| Freebies | Free Trial | Add to Bookmark | Search | Link to Us |
Copyright © 2006 SqlRef.com. All rights reserved.