The difference between join in SQL and the usage of join

Source: Internet
Author: User

1. Join has left Join,right Join,inner join these three kinds, two tables do a Cartesian product, and then select the result set, select the part that satisfies the condition as the result.

    • Join (INNER JOIN): Returns a row if there is at least one match in the table (Note: INNER join is the same as join.) )
    • Left JOIN (outer join:): Returns all rows from the left table, even if there is no match in the right table (note: In some databases, the Ieft join is called the OUTER join. )
    • Right join: Returns all rows from the right table, even if there are no matches in the left table (note: In some databases, the correct join is called a OUTER join. )
    • Full join (all outer joins): Returns a row whenever a match exists in one of the tables (note: In some databases, the complete join is called the full OUTER join. )

2.in is used as a conditional query:

SELECT * from Persons where lastName in (' Adams ', ' Carter ')

Two statements, you can use the SQL optimizer to see how efficiently they perform:

Select COUNT (Distinct (typ.orig_id)) from Sch. Nwstyp Typ left outer join Sch. Nwsatt att on typ.orig_id = att. orig_id where Att.fld_code = ' 4 ' and att.fld_val = ' 1101 ';
Select COUNT (Distinct (typ.orig_id)) from Sch. Nwstyp Typ,sch. Nwsatt att where typ. Typ_code = ' 1501 ' and typ.orig_id = att. orig_id and Att.fld_code = ' 4 ' and att.fld_val = ' 1101 ';

The second SQL above is used by default with the inner join.

The online search also mentions exist.

Found an article:

Http://weblogs.sqlteam.com/mladenp/archive/2007/05/18/60210.aspx

Can see.

The difference between join in SQL and the usage of join

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.