The difference between inner Join,outer join and cross join in SQL

Source: Internet
Author: User
Tags joins

Using the Join table, the defect is inner join, the left join used in development and the right join belong to outer join,outer join including full join

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 joins TableB on tablea.name = tableb.name icons similar to 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 joins TableB on tablea.name = Tableb.name can be found by means of NULL to find no matching values: SELECT * from TableA full O Uter JOIN TableB on tablea.name = Tableb.namewhere tablea.id are 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

The difference 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.