EXISTS Operator

EXISTS operatori bir subso'rovda har qanday yozuv mavjudligini tekshirish uchun ishlatiladi.

SU

SQL EXISTS Operatori

EXISTS operatori bir subso'rovda har qanday yozuv mavjudligini tekshirish uchun ishlatiladi.

EXISTS operatori subso'rov bir yoki bir nechta yozuv qaytarsa, TRUE qiymatini qaytaradi.

EXISTS Sintaksisi

SELECT column_name(s)
FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE condition);

Demo Ma'lumotlar Bazasi

Ushbu o'quv qo'llanmada Northwind namunaviy ma'lumotlar bazasidan "Products" jadvalidan bir tanlov:

ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18
2Chang1124 - 12 oz bottles19
3Aniseed Syrup1212 - 550 ml bottles10
4Chef Anton's Cajun Seasoning2248 - 6 oz jars22
5Chef Anton's Gumbo Mix2236 boxes21.35

Va "Suppliers" jadvalidan bir tanlov:

SupplierIDSupplierNameContactNameAddressCityPostalCodeCountry
1Exotic LiquidCharlotte Cooper49 Gilbert St.LondonEC1 4SDUK
2New Orleans Cajun DelightsShelley BurkeP.O. Box 78934New Orleans70117USA
3Grandma Kelly's HomesteadRegina Murphy707 Oxford Rd.Ann Arbor48104USA
4Tokyo TradersYoshi Nagase9-8 Sekimai Musashino-shiTokyo100Japan

SQL EXISTS Misollari

Quyidagi SQL bayonoti TRUE qaytaradi va narxi 20 dan kam bo'lgan mahsulotga ega yetkazib beruvchilarni ro'yxatga oladi:

SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.SupplierID AND Price < 20);

Quyidagi SQL bayonoti TRUE qaytaradi va narxi 22 ga teng bo'lgan mahsulotga ega yetkazib beruvchilarni ro'yxatga oladi:

SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.SupplierID AND Price = 22);

Ushbu sahifada

Xato haqida xabar berish