Power Selecting - Distinct
(Page 3 of 6 )
Occasionally one or more records may have the same information for a particular field and so a query may return duplicate results. As an example, consider a query to display the home states of those in the Clients table.
SELECT State FROM Clients;
State ----- NY AL RI TN WA CA CA CA AZ TX IN MA |
12 sets were returned even though there are only 10 distinct states in the table. California may be a large state, but it's certainly not desirable to count it three times!
Eliminating duplicates and returning only unique values can be done by using the DISTINCT keyword which follows SELECT.
SELECT DISTINCT State FROM Clients;
State ----- NY AL RI TN WA CA AZ TX IN MA |
Now 10 distinct states are returned from the table. DISTINCT has removed the repetitive results and the query returns a set of unique values.
Next: As >>
More Database Articles Articles
More By bluephoenix