SQL: DISTINCT clause
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:
Consider a table of lastnames, where you have the last name, 'Jones', repeated numerous times. This code returns only one 'Jones'.
This SQL statement will return each unique city and state combination.
|Copyright © 2005-2007 www.WebCheatSheet.com All Rights Reserved.|