And, Where usage tips And left join prompts And precautions with +

Source: Internet
Author: User

Please pay attention to the abuse of 1and and where.

The effect of the three paragraphs below must be different.
(1)
Copy codeThe Code is as follows:
SelectA. a1, B. b3
FromAleftjoinB
OnA. a2 = B. b2
WhereA. a3 = 1
AndB. b3 = 2

First join left and then filter B in the join result. b3 = null, then you add B after where. b3 = 2 then B in the result. b3 is certainly not null.
(2)
Copy codeThe Code is as follows:
SelectA. a1, B. b3
FromAleftjoinB
OnA. a2 = B. b2
AndB. b3 = 2
WhereA. a3 = 1

Leave the b3 = 2 condition of B before Association, and then associate it on the left. This result may be null in B. a3.
(3)
Copy codeThe Code is as follows:
SelectA. a1, B. b3
FromAleftjoinB
OnA. a2 = B. b2
AndB. b3 = 2
AndA. a3 = 1

Before Association, the B3 = 2 in B and a3 = 1 in A are dropped before Association. Then, this result may be null in B. b3.

So when you use where and, pay more attention to the location.

2. Use + for left-join defects. A solution may be available for future use.
(1)
Copy codeThe Code is as follows:
SelectA. a1, B. b3
FromA, B
WhereA. a2 = B. b2 (+)
AndA. a3 (+) = 1
AndB. b3 (+) = 2

This condition should be the same as that of (1) in 1.

First join left and then filter B in the join result. b3 = null, then you add B after where. b3 = 2 then B in the result. b3 is certainly not null.
That is to say, using + for left join is not used. leftjoin is flexible. You can see if there is any good solution later.

Related Article

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.