How to use MySQL join

Source: Internet
Author: User
Tags joins

JOIN is broadly divided into three categories as follows:

INNER Join(inner join, or equivalent connection): Gets a record of two tables that have a connection matching relationship.

Left join: Gets the left table (table1) full record, that is, the right table (table2) has no corresponding matching record.

Right join: In contrast to the left join, get the full record of the right table (table2), which is the Table1 with no matching records.

Note:MySQL does not support full join, but you can use the Union keyword to merge the LEFT join with the right join to simulate full join.

I. Inner JOIN

Inner joins, also known as equivalent connections, inner join produces a set of data that meets both A and B.

SELECT * FROM table1 inner joins table2 on table1.name = Table2.name;

Second, left Join

Left join, (or left outer join: equivalent in MySQL, we recommend using the left join. A left connection from the left table (A) produces a complete set of records, with matching records (right table (B)). If there is no match, the right side will contain null.

SELECT * FROM table1 left JOIN table2 on table1.name = Table2.name;

Third, right Join
SELECT * FROM table1 right JOIN table2 on table1.name = Table2.name;

Update:

UPDATE table1 left JOIN table2 on table1.id=table2.a_id SET table1.title= ' aaaaa ', table2.body= ' bbbb ' WHERE table1.id=1www

Delete:

DELETE table1,table2 from table1 INNER JOIN table2 on table1.uid=table2.uid WHERE table1.uid= ' 168953 '

How to use MySQL join

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.