मुख्य सामग्री पर जाएं
eLearner.app
मॉड्यूल 2 · पाठ 2 का 4पाठ्यक्रम में 6/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 प्रयासों के बाद समाधान उपलब्ध है