דילוג לתוכן המרכזי
eLearner.app
מודול 2 · שיעור 2 מתוך 46/57 בקורס~6 min
שיעורי מודול (2/4)

ערכים ייחודיים עם 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

פעילות גופנית#sql.m2.l2.e1
ניסיונות: 0טוען...

List the distinct department_id values present among employees (duplicates must disappear).

טוען עורך...
הצג רמז

Add DISTINCT right after SELECT to remove duplicates.

הפתרון זמין לאחר 3 ניסיונות

Review exercise

פעילות גופנית#sql.m2.l2.e2
ניסיונות: 0טוען...

List the distinct (department_id, hired_on) pairs for employees hired from 2020 onwards.

טוען עורך...
הצג רמז

DISTINCT evaluates uniqueness over the combination of all listed columns.

הפתרון זמין לאחר 3 ניסיונות