SQL Server 2012-Multi-table connection query

Source: Internet
Author: User

--Cross join produces a Cartesian value (x*y) SELECT * from Student crosses Join dbo. ClassInfo--Another way of writing select * from Student, ClassInfo--INNER join (Inner can omit) select *from Student JOIN dbo. ClassInfo on dbo. Student.class = dbo. classinfo.id;--Inner Join SELECT *from Student Inner join dbo. ClassInfo on dbo. Student.class = dbo.  Classinfo.id; --on condition, usually the primary foreign key, but not limited to the primary foreign key--on condition, which allows multiple, and possibly a select *from Student INNER JOIN dbo for a table. ClassInfo on dbo. Student.class = dbo. Classinfo.idand dbo. Student.class in--increases the query condition for the Student table-not equal to (the Cartesian value minus the equal value) SELECT *from Student INNER JOIN dbo. ClassInfo on dbo. Student.class <> dbo. classinfo.id;--from the class table to query the class in the department select t1.*, T2. ClassName from dbo. ClassInfo as T1inner JOIN dbo. ClassInfo as T2 on T1. Pid=t2. id--left Joinselect *from Student left JOIN dbo. ClassInfo on dbo. Student.class = dbo. classinfo.id;--Right Joinselect *from Student right JOIN dbo. ClassInfo on dbo. Student.class= dbo. classinfo.id;--Full External Connection Select *from Student complete OUTER JOIN dbo. ClassInfo on dbo. Student.class = dbo. classinfo.id;--outside the connection and the difference between the internal connection is:--internal connection, the on condition does not conform, will filter out the data--outer connection, to preserve the table-based, on the condition of display data, otherwise display null--union vertical connection Select Stuid, Stuname,stuenname,stuage,stubirthdayfrom Student where Stuid<=2unionselect stuid,stuname,stuenname,stuage, STUBIRTHDAYFROM dbo. Student where stuid>2--union to repeat select Stusexfrom Student where Stuid<=2unionselect stusexfrom dbo. Student where stuid>2--union shows all select Stusexfrom Student where Stuid<=2union allselect stusexfrom dbo. Student where stuid>2--except difference set, excluding select Stuid,stuname,stuenname,stuage,stubirthdayfrom Student exceptselect StuI D,STUNAME,STUENNAME,STUAGE,STUBIRTHDAYFROM dbo. Student where Stuid<=2--intersect intersection select Stuid,stuname,stuenname,stuage,stubirthdayfrom Student where stuid>= 2ExceptSELECT stuid,stuname,stuenname,stuage,stubirthdayfrom dbo. Student WHERE stuid<=3

  

SQL Server 2012-Multi-table connection query

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.