SQL Server Table Links query

Source: Internet
Author: User

I missed it.

SELECT * FROM student,score--Cartesian product

you can think of it as a multidimensional function in C #, and every piece of data in each table will be printed with all the data from the second table.

Connections for two tables:

First method (more commonly used)

Select Student.sno, sname, degree

From Student,score---- when querying a column name in two tables, it is sometimes stated that the column in that table is used to indicate the column name (Student.sno).

Where Student.sno=score.sno--a column that is common to a table so that the two tables are connected

The second method of

Select CNO, (select sname from student where Student.sno=score.sno), the degree from score routines are the same, with different locations

The third method of

Select Student.sno, sname,cno,degree from student joins score on Student.sno=score.sno

---//inner join (default)//left join (left table as the primary table)//right join (the right table is the main table)

Connection of three tables

First method (same as above two tables)

Select Student.sno, sname, CNO, degree, name--- if degree+10, name+ ' classmate ' result is: increase in the value of 10 characters after adding students, the value type will be calculated, the string class will be spliced

From Student,score,course---- when the column name of a query is not only present in 1 tables, it is sometimes used to indicate that the point column name (STUDENT.SNO) is the one in the table.

where Student.sno=score.sno

and Score.cno=course.cno

The second method of

Select Student.sno, sname, CNO, degree, name

From student join score

On Student.sno=course.sno

Join Course

On Score.cno=course.cno

Vertical link data types to be consistent

Between two tables with a Union

Give me a chestnut:

Select Tname name, Tsex sex, tbirthday birthday from teacher
Union
Select Sname, ssex,sbirthday from student

SQL Server Table Links 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.