SQL Server Fundamentals: Join

Source: Internet
Author: User
Tags joins

3.Join (hemp egg nonsense not much to say there is a picture of the truth)

Test Data Script

1 CREATE TABLEAtable2   ( 3s#INT, 4Snamenvarchar( +), 5SageINT, 6Sfromnvarchar(8) 7   ) 8 9 Ten  Insert  intoAtable One  Select 1N'Liu', -N'A' Union  All A  Select 2N'Money Two', +N'A' Union  All -  Select 3N'Zhang San', -N'A' Union  All -  Select 4N'John Doe', -N'A'  the  -   -  -  +  CREATE TABLEbtable -   (  +s#INT,  ASnamenvarchar( +),  atSageINT,  -Sfromnvarchar(8)  -   )  -  -  -  Insert  intobtable in  Select 1N'John Doe', -N'B' Union  All -  Select 2N'Tom', +N'B' Union  All to  Select 3N'Liu', -N'B' Union  All +  Select 4N'Jack', -N'B'
View Code

Data Sheet

1) Cross join: No connection conditions are required for the crossover connection. Two tables of data are directly performed by Cartesian product operations.

SELECT * from Atable as A cross  join btable as B ORDER by a.s#

2) INNER JOIN = = Join within joins is the ability to list the records associated with two tables, which must be associated records.

SELECT * from Atable as A  INNER joins btable as B on a.sname = B.sname

3) The LEFT outer join = = to a full set of table B, while the match in a table has a value, and no match is substituted with a null value.

SELECT * from Atable as A left outer joins btable as B on a.sname = B.sname

4) Right outer join = = Right Jion produces the full set of table A, while the match in B table has a value, and no match is substituted with a null value.

SELECT * from Atable as A right outer joins btable as B on a.sname = B.sname

5) Full outer join = = Full Join produces A and B's set. It is important to note, however, that for records that do not have a match, NULL is the value.

6) The Union and union all are different when the union is going to be the same, and the Union is not going to be heavy.

Select Sname from Atable  Union  Select Sname from  btable  SELECT Sname from Atable  UNION all SELECT Sna Me from  btable  

SQL Server Fundamentals: Join

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.