Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet153/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   149   150   151   152   153   154   155   156   ...   443
Bog'liq
BookSQL

Self Cross Joins

You can join multiple instances of the same table. This capability is known as a self join and is sup-

ported with all fundamental join types (cross joins, inner joins, and outer joins). For example, the fol-

lowing query performs a self cross join between two instances of the Employees table.

SELECT 

  E1.empid, E1.firstname, E1.lastname, 

  E2.empid, E2.firstname, E2.lastname 

FROM HR.Employees AS E1  

  CROSS JOIN HR.Employees AS E2;

This query produces all possible combinations of pairs of employees. Because the Employees table 

has 9 rows, this query returns 81 rows, shown here in abbreviated form.

empid  firstname  lastname        empid  firstname  lastname 

------ ---------- --------------- ------ ---------- --------- 

1      Sara       Davis           1      Sara       Davis 

2      Don        Funk            1      Sara       Davis 

3      Judy       Lew             1      Sara       Davis 

4      Yael       Peled           1      Sara       Davis 

5      Sven       Buck            1      Sara       Davis 

6      Paul       Suurs           1      Sara       Davis 

7      Russell    King            1      Sara       Davis 

8      Maria      Cameron         1      Sara       Davis 

9      Zoya       Dolgopyatova    1      Sara       Davis 

www.it-ebooks.info



102  

Microsoft SQL Server 2012 T-SQL Fundamentals

1      Sara       Davis           2      Don        Funk 

2      Don        Funk            2      Don        Funk 

3      Judy       Lew             2      Don        Funk 

4      Yael       Peled           2      Don        Funk 

5      Sven       Buck            2      Don        Funk 

6      Paul       Suurs           2      Don        Funk 

7      Russell    King            2      Don        Funk 

8      Maria      Cameron         2      Don        Funk 

9      Zoya       Dolgopyatova    2      Don        Funk 

... 


 

(81 row(s) affected)

In a self join, aliasing tables is not optional. Without table aliases, all column names in the result of 

the join would be ambiguous.




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   149   150   151   152   153   154   155   156   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish