Differences between inner JOIN, outer join, and Cross join in SQL

Source: Internet
Author: User
Tags joins

By default, the inner join, the left join and the right join used in development belong to the outer join, and the outer join also includes the full join. Below I let you know the difference by the icon.
There are two tables, table A is the one on the left. Table B is the list on the right. Each of them has four records, of which two records have the same name:

The result of the 1.INNER JOIN is the intersection of AB

SELECT * from TableA INNER JOIN TableB on tablea.name = Tableb.name

A 2.LEFT [OUTER] JOIN produces a full set of table A, whereas a match in B table has a value, and no match is substituted with a null value.
SELECT * from TableA left OUTER joins TableB on tablea.name = Tableb.name

A 3.RIGHT [OUTER] JOIN produces a full set of Table B, and a match in table A has a value, and no match is substituted with a null value.
SELECT * from TableA right OUTER JOIN TableB on tablea.name = Tableb.name
Icons are similar to the left join.

The 4.FULL [OUTER] JOIN produces a and B's set. For records that do not have a match, NULL is the value.
SELECT * from TableA full OUTER JOIN TableB on tablea.name = Tableb.name
You can find the value without matching by the IS null:
SELECT * from TableA full OUTER JOIN TableB on tablea.name = Tableb.name
WHERE tablea.id is null OR tableb.id is null

5. Cross joins a n*m combination of the data from table A and table B, the Cartesian product. If this regular session produces 4*4=16 records, we must filter the data during the development process, so this is seldom used.
SELECT * from TableA cross JOIN TableB
We believe that the difference between inner join, outer join and Cross join is at a glance.

Differences between inner JOIN, outer join, and Cross join in SQL

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.