Home page
 
 Home 
 ASP 
 PHP 
 SQL 
 HTML 
 JavaScript 
 Search 
 Contact 
 
Search
or browse popular tags
Subscription

Sign up for the free email newsletter for new tips, tutorials and more. Enter your email address below, and then click the button.

Privacy Policy

RSS Twitter

SQL: DISTINCT clause

Print

Select lets you use the Distinct keyword to eliminate duplicate rows from the query results. Distinct is very useful in queries where you simply want to know if a value is present in a table and are not interested in how many times it occurs. Distinct itself can only be used once in a Select statement. However, you can specify more than one column after Distinct. In this case, SQL will eliminate those rows where the values are the same in all the columns.

The syntax for the Distinct clause is:

SELECT DISTINCT column_name
FROM derived_table
WHERE conditions

Example #1

SELECT DISTINCT OWNERLASTNAME
FROM AntiqueOwners

Consider a table of lastnames, where you have the last name, 'Jones', repeated numerous times. This code returns only one 'Jones'.

Example #2

SELECT DISTINCT CITY,STATE
FROM EmployeeAddressTable

This SQL statement will return each unique city and state combination.


If you'd like to see how it works, enter SQL statement and press Execute
 




Tags:

Add To: Add to dzone dzone | Digg this digg | Add to del.icio.us del.icio.us | Stumble it stumbleupon

  • Comments





Copyright © 2005-2023             www.WebCheatSheet.com All Rights Reserved.