Left join of database Basics

Source: Internet
Author: User
The left Outer Join adds unmatched data in the master table based on the equijoin. This afternoon, I processed an SQL statement and joined the table through leftouterjoin (soasrightleftouterjoin. seeing this syntax, intuitively, the number of query results should be the number of records returned by the master table after Where (The Where description is omitted below) until today

The left Outer Join adds unmatched data in the master table based on the equijoin. This afternoon, I processed an SQL statement and joined the table through left outer join (so as right left outer join. seeing this syntax, intuitively, the number of query results should be the number of records returned by the master table after Where (The Where description is omitted below) until today

The left Outer Join adds unmatched data in the master table based on the equijoin.

This afternoon, I processed an SQL statement and joined the table through left outer join (so as right left outer join. seeing this syntax, intuitively, the number of query results should be the number of records returned by the master table after Where (The Where description is omitted below), until this afternoon I wrote an SQL statement, the total number of returned records table has more than the total number table. nini!

I think it's a bit unacceptable, why? The reference materials did not fully understand why, and I did not understand why after searching for half a day of data.

So the buddy next to him talked about it. The Buddy looked at it and said, have you considered repeated sub-table records! Instantly understood ....

Summary:

CREATE TABLE a( A INT)CREATE TABLE ab( B INT)INSERT INTO a VALUES(1);INSERT INTO a VALUES(2);INSERT INTO ab VALUES(1);INSERT INTO ab VALUES(1);INSERT INTO ab VALUES(1);SELECT * FROM aSELECT * FROM a LEFT OUTER JOIN  abON (a.a=ab.b)

The query result is:

  

1 1 1
211
311
42

The main purpose of recording this incident is to explain that the first response is not necessarily correct during work, when we are deeply immersed in it, we may wish to find an outsider to help us deal with it. It is called the viewer, ^ _ ^. During the discussion, we should also pay attention to the objective description of the problem and try not to drag our friends into the trap of thinking.

Connection references: http://liuzidong.iteye.com/blog/892319

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.