UNION, UNION ALL, EXCEPT, INTERSECT
*** EXCEPT, INTERSECT komutları SQL Server 2008 de kullanılabilir ! Diğer deyimler önceki sürümlerde kullanılabiliyordu.
-- sql server 2008 ile gelen yeni deyimler except ve intersect -- geçici tabloları yapalım ve test kayıtları ekleyelim CREATE TABLE #UnionTest1 ( idcol int IDENTITY, col2 char(3), ); CREATE TABLE #UnionTest2 ( idcol int IDENTITY, col4 char(3), ); INSERT INTO #UnionTest1 VALUES ('AAA'), ('BBB'), ('CCC'); INSERT INTO #UnionTest2 VALUES ('CCC'), ('DDD'), ('EEE');
-- örnekler --
-- her iki ablodaki benzersiz tüm kayıtları listeliyor. bir nevi distinct select col2 from #UnionTest1 UNION select col4 from #Uniontest2
--her iki tablodaki tüm kayıtları koşulsuz listeler select col2 from #UnionTest1 union all select col4 from #UnionTest2
--ilk tablodaki benzersiz kayıtları listeler. ve ikinci tablodan herhangi bir veri almaz --ikinci tablo sadece kontrol için kullanılmış olur select col2 from #uniontest1 except select col4 from #uniontest2
--alternatif select select col2 from #uniontest1 as t1 where not exists(select col4 from #uniontest2 where col4 = t1.col2)
--her iki tabloda ortak/benzer kayıtları listeler select col2 from #uniontest1 intersect select col4 from #uniontest2
--alernatif select select col2 from #uniontest1 as t1 where exists(select col4 from #uniontest2 where col4 = t1.col2)
------------- http://www.kasatakip.com - Kasa Takip | http://www.caritakip.com - Cari Takip | http://www.evraktakip.com - Evrak Takip | http://www.etasqlmobil.com - ETA SQL Mobil
|