2017-3-13 SQL Server Table connections

Source: Internet
Author: User
Tags joins

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

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.