About out-of-database connections and internal and cross-joins

Source: Internet
Author: User
Tags joins

I. External connections

1.left Join

Example: SQL statement: SELECT * FROM student left join course on Student.id=course.id

The left OUTER join contains all the rows from the left table in a left join, and if there is no match on the right table in the table, the portion of the right table in the corresponding row in the result is all empty (null).

2. Right-connect to the join on either or outer join

SQL statement: SELECT * FROM student right join course on student.id=course.id

The right outer join contains all the rows in the right table, and if a row in the left table does not match on the right table, the portion of the corresponding left table in the result is all empty (null).

3. Fully external connection full join or outer join

SQL statement: SELECT * FROM student full join course on student.id=course.id

A full outer join contains all of the rows in both the left and right tables of the complete join, and if there is no match in the left table for a row in the table, the portion of the right table in the corresponding row in the result is all empty (null), and if a row in the left table does not match in the right table, the portion of the left table

Two. Internal connection

INNER JOIN join or INNER JOIN

SQL statement: SELECT * FROM student inner JOIN course on student.id=course.id

This is equivalent to: SELECT * from Student,course where student.id=course.id

Three. Cross-connect

1. Concept: A cross join without a WHERE clause will produce a Cartesian product of the table involved in the connection. The number of rows in the first table multiplied by the number of rows in the second table equals the size of the Cartesian product result set.

SQL statement: SELECT * FROM student Cross Join course

If we add a WHERE clause to this SQL at this time such as Sql:select * from Student Cross join course where student.id=course.id

The result set that matches the condition is returned, and the result is the same as the inner join shows.

About out-of-database connections and internal and cross-joins

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.