EXCEPT Komutu

Aslında Not in veya Not exists komutları ile de aynı sonucu alacağımız bir komuttur Except. 2 farklı sorgudan dönen sonuç kümelerini karşılaştırarak sadece ilk belirtilen sorgu sonucunda olan fakat ikinci sorgu sonucunda olmayan kayıtları listeler.
Bir örnek vermek istersek Product tablosunda olan fakat WorkOrder tablosunda olmayan kayıtları 3 farklı komutla listeleyebiliriz.

1) Except ile:
select ProductID from Production.Product
except
select ProductID from Production.WorkOrder


2) Not in ile:
select ProductID from Production.Product
where ProductID not in(select ProductID from Production.WorkOrder)


3)Not exists ile:
select ProductID from Production.Product p
where not exists(select top 1 1 from Production.WorkOrder wo where p.ProductID=wo.ProductID)

Yorumlar

Bu blogdaki popüler yayınlar

Natural Key ve Surrogate Key Nedir?

PL/SQL'de DEĞİŞKEN TANIMLAMA, EKRANA YAZI YAZDIRMA ve GÜNCELLEME

SQL Server Analysis Services 2012’de Multidimensional Model ve Tabular Model