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

Source: Internet
Author: User

Excerpt from: http://blog.csdn.net/scythe666/article/details/51881235

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:

1.INNER JOIN   Produces a result of the intersection of AB

select * from Tablea inner join tableb on tablea.name = tableb.name
      & nbsp   
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 join tableb on tablea.name = tableb.name
        &NBS P  
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. The
SELECT * from TableA right OUTER join tableb on tablea.name = Tableb.name
icon is similar to a 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.