Table joins are divided into horizontal table joins and longitudinal table joins
There are three ways to connect a horizontal table:
1. Select column name, column name from table name, table name where table name. column name = table name. Column Name
Select Student. Sno,sname,cno,degree from Student,score
where Student.sno = Score.sno
2, sub-query method
Select Sno,sname, (select CNO from score where Student.sno=score.sno) from Student
3. Select column name, column name from table name join table name on table name. column name = table name. Column Name
Select Student.sno,sname,score.cno,degree,cname
From Student join score on Student.sno=score.sno
Join Course on score.cno = Course.cno
Vertical Table Connection: (Note: Two tables must be the same number of columns, corresponding column data types must be the same)
Select column name, column name from table name Union Select column name, column name from table name
Select Sno Number, sname name, ssex sex, sbirthday birthday from Student
Union
Select Tno,tname,tsex,tbirthday from Teacher
--------------------------------------------------------------------------------------------------------------- -----------------------------
Flexible usage
Select student.sno,sname+ ' classmate ', Cname,abs (degree+10)
From Student,score,course
where Student.sno=score.sno and Score.cno=course.cno
and student. sno= ' 107 '
2017-3-13 SQL Server Table connections