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.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести