Given a PLAYERS table with following columns and constraints:
-------------------------
| Name    | Constraint  |
|-----------------------|
| PLAYER  | Primary Key |
| TEAM    | Foreign key |
| AGE     |             |
-------------------------
It contains football players from different teams.
Is it necessary to use DISTINCT keyword in the following query to get a list of unique values of TEAM:
SELECT DISTINCT TEAM FROM PLAYERS
Explanation
PLAYERS table may contain several players from the same TEAM. Therefore, following query:
SELECT TEAM FROM PLAYERS
will return duplicate values for TEAM in this case.
So, yes, it is necessary to use DISTINCT keyword in this context.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback