SQL JOIN INNER left right full

Source: Internet
Author: User

1. Referencing 2 tables (effects with inner join)

1 SELECT  from WHERE =

2.INNER Join Join (returns a row if there is at least one match in the table)

1 SELECT  from INNER JOIN  on = ORDER  by Persons.lastname

3.LEFT join: Even if there is no match in the right table, all rows are returned from the left table (all people one and their subscription, even if not ordered, will return) (the left JOIN keyword returns all rows from the table (Persons), even if the right table (Orders) There are no matching rows in the. )

1 SELECT Persons.lastname, Persons.firstname, Orders.orderno 2  from Persons 3  Left JOIN Orders 4  on Persons.id_p=orders.id_p5ORDER by Persons.lastname

4.RIGHT join: All rows are returned from the right table, even if there is no match in the left table (the right JOIN keyword returns all rows from that table (Orders), even if there are no matching rows in the left table (Persons). )

1 SELECT Persons.lastname, Persons.firstname, Orders.orderno 2  from Persons 3  Right JOIN Orders 4  on Persons.id_p=orders.id_p5ORDER by Persons.lastname

5.FULL JOIN: Returns a row whenever there is a match in one of the tables (the full JOIN keyword returns all rows from the left table (Persons) and the right table (Orders). If the rows in "Persons" do not match in the table "orders", or if the rows in "orders" do not have a match in the table "Persons", the rows are also listed. )

1 SELECT Persons.lastname, Persons.firstname, Orders.orderno 2  from Persons 3  Full JOIN Orders 4  on Persons.id_p=orders.id_p5ORDER by Persons.lastname

SQL JOIN INNER left right full

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.