SQL DISTINCT is a SQL keyword that specifies that only distinct / non-duplicate results are to be returned.
DISTINCT can apply to single columns or to multiple columns.
The DISTINCT keyword can help to understand information. For example, a query containing DISTINCT could return a non-duplicated list of cities where a company does business.
SQL DISTINCT is used as follows.
SQL DISTINCT Syntax
The word DISTINCT can be placed in front of a single column name or a number of column names. When in front of multiple column names, a distinct combination is returned.
SQL DISTINCT Example
The following example a DISTINCT list of region_nbr referenced in the branch table is returned.
Here are the contents of the table:
Table: BRANCH
branch_nbr | branch_name | region_nbr | employee_count |
108 | New York | 100 | 10 |
110 | Boston | 100 | 6 |
212 | Chicago | 200 | 5 |
404 | San Diego | 400 | 6 |
415 | San Jose | 400 | 3 |
This SQL Statement with DISTINCT is executed:
Here is the result.
region_nbr |
100 |
200 |
400 |
Advertisements:
Infogoal.com is organized to help you gain mastery.
Examples may be simplified to facilitate learning.
Content is reviewed for errors but is not warranted to be 100% correct.
In order to use this site, you must read and agree to the
terms of use, privacy policy and cookie policy.
Copyright 2006-2020 by Infogoal, LLC. All Rights Reserved.