Modul 2 · Pelajaran 2 dari 46/57 dalam kursus~6 min
Pelajaran modul (2/4)
Nilai unik dengan DISTINCT
Sometimes a column contains repeated values and you only care about the
list of distinct values. The keyword DISTINCT placed right after
SELECT removes duplicates from the result:
SQL
SELECT DISTINCT <colonne>
FROM <tabella>
[WHERE <condizione>];Uniqueness is evaluated over the combination of all listed columns. If you list two columns, two rows are considered equal only when both values match.
Examples
SQL
-- Le città in cui abbiamo almeno un dipartimento:
SELECT DISTINCT city FROM departments;
-- Le coppie (dipartimento, città) presenti (qui ognuna unica):
SELECT DISTINCT department_id, hired_on
FROM employees;Try it
Latihan#sql.m2.l2.e1
Upaya: 0Memuat…
List the distinct department_id values present among employees (duplicates must disappear).
Memuat editor…
Tunjukkan petunjuk
Add DISTINCT right after SELECT to remove duplicates.
Solusi tersedia setelah 3 upaya
Review exercise
Latihan#sql.m2.l2.e2
Upaya: 0Memuat…
List the distinct (department_id, hired_on) pairs for employees hired from 2020 onwards.
Memuat editor…
Tunjukkan petunjuk
DISTINCT evaluates uniqueness over the combination of all listed columns.
Solusi tersedia setelah 3 upaya