Left JOIN and join multiple table joins

Source: Internet
Author: User
Tags joins

Four sheets contract, customer, Customer3, Customer4:



This is a more familiar 3-sheet connection
SELECT *
From Test.contract A
JOIN Test.customer b on a.num = b.num2
JOIN test.customer3 C on a.num = C.NUM3;

The connection is not necessarily followed by a join to the first table.
SELECT *
From Test.contract A
JOIN Test.customer b on a.num = b.num2
Left JOIN test.customer4 D on b.num2 = d.num4;

SELECT *
From Test.contract A
JOIN Test.customer b on a.num = b.num2
Left JOIN test.customer4 D on a.num = d.num4;
This is the same as the result of the previous sentence.
Note that the bold place, I think, is to take A and B's join result set and then the D table left join, at which point a B is still in scope. To avoid confusion, you can set the result of a B as an individual name tmp
SELECT * FROM
(SELECT *
From Test.contract A
JOIN Test.customer b on a.num = B.NUM2) tmp
Left JOIN test.customer4 d on tmp.num = D.NUM4;
Results Ibid.
PS: Multiple table Join table connection order from left to right

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.