SQL Server internal connection, left outer join, right outer join, full connection, cross Lianjie

Source: Internet
Author: User

Data preparation:
Create TableT1 (Avarchar(Ten) not NULL, Bvarchar(Ten) not NULL, Ctinyint  not NULL);Create TableT2 (Bvarchar(Ten) not NULL, Etinyint  not NULL);Insert  intoT1Values('A1','B1',5),('A1','B2',6),('A2','B3',8),('A2','B4', A);Insert  intoT2Values('B1',3),('B2',7),('B3',Ten),('B3',2),('b5',2);Select *  fromT1;Select *  fromT2;
Results:
1 A B C2 ---------- ---------- ----3A1 B154A1 B265A2 B386A2 B4 A7 8(4row affected)9 Ten B E One ---------- ---- AB13 -B27 -B3Ten theB32 -B52 -  -(5Row affected)
1. Internal connection
1 Select *  fromT1Inner JoinT2 onT1. B=t2.b2 3 A b C B E4 ---------- ---------- ---- ---------- ----5A1 B15B136A1 B26B277A2 B38B3Ten8A2 B38B32
2. Left Outer connection
1 Select *  fromT1 Left outer JoinT2 onT1. B=t2.b2 3 A b C B E4 ---------- ---------- ---- ---------- ----5A1 B15B136A1 B26B277A2 B38B3Ten8A2 B38B329A2 B4 A   NULL       NULL
3. Right outer connection
1 Select *  fromT1 Right outer JoinT2 onT1. B=t2.b2 3 A b C B E4 ---------- ----------   ---- ---------- ----5A1 B15B136A1 B26B277A2 B38B3Ten8A2 B38B329 NULL     NULL     NULLB52
4. Fully connected
1 Select *  fromT1 Full outer JoinT2 onT1. B=t2.b2 3 A b C B E4 ---------- ---------- ---- ---------- ----5A1 B15B136A1 B26B277A2 B38B3Ten8A2 B38B329A2 B4 A     NULL      NULLTen NULL       NULL       NULLB52
5. Cross connection (Cartesian product)
1 Select *  fromT1 Cross JoinT22 3 A b C B E4 ---------- ---------- ---- ---------- ----5A1 B15B136A1 B15B277A1 B15B3Ten8A1 B15B329A1 B15B52TenA1 B26B13 OneA1 B26B27 AA1 B26B3Ten -A1 B26B32 -A1 B26B52 theA2 B38B13 -A2 B38B27 -A2 B38B3Ten -A2 B38B32 +A2 B38B52 -A2 B4 AB13 +A2 B4 AB27 AA2 B4 AB3Ten atA2 B4 AB32 -A2 B4 AB52

SQL Server internal connection, left outer join, right outer join, full connection, cross Lianjie

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.