SELECT DISTINCT buyrug'i

SELECT DISTINCT buyrug'idan, bir-biriga o'xshash bo'lmagan, ya'ni unikal qiymatlarni olish uchun foydalaniladi.Jadval, ustun ichida ko'pincha takroriy qiymatlar qamrab olingan bo'ladi; va ba'zida siz faqatgina o'xshash bo'lmagan qiymatlarni ro'yhatini olishni istashingiz mumkin.

SELECT DISTINCT sintaksis

SELECT DISTINCT ustun1, ustun2, ...
FROM jadval_nomi;


Quyida, "Murad Buildings" namuna uchun keltirilgan ma'lumot bazasidagi chet ellik "Xaridorlar" jadvalidan tanlanma ro'yhati keltirilgan:

CustomerID CustomerName ContactName Address City PostalCode Country
1
 
Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany
2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución 2222 México D.F. 05021 Mexico
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
4
 
Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
5 Berglunds snabbköp Christina Berglund Berguvsvägen 8 Luleå S-958 22 Sweden

Yuqoridagi namunani DISTINCT-siz, SELECT orqali tanlab olamiz:

Quyidagi SQL buyruq "Xaridorlar" jadvalidagi "Country" ustunidan barcha qiymatlar(o'xshash qiymlarni ham)ni tanlab oladi:

SELECT Country FROM Customers;

Endi ushbu namunani, SELECT DISTINCT bilan ko'rsak:

SELECT DISTINCT Country FROM Customers;

Quyidagi SQL buyruqda, xaridorlarning bir-biriga o'xshash bo'lmagan holda davlatlar sonini chiqarib beradi:

SELECT COUNT(DISTINCT Country) FROM Customers;