--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