MySQL internal connection, left join, right connection

Source: Internet
Author: User
Tags joins

Record memo, initial data is as follows:

DROP TABLE IF EXISTSt_demo_product;CREATE TABLE IF  not EXISTSt_demo_product (proidint( -), Pronamevarchar( -), priceint(Ten),    PRIMARY KEY(proid)) ENGINE=InnoDBDEFAULTCHARSET=GBK;DROP TABLE IF EXISTSt_demo_operation;CREATE TABLE IF  not EXISTSt_demo_operation (Opidint(Ten), Proidint( -), Opcountint(Ten),    PRIMARY KEY(Opid)) ENGINE=InnoDBDEFAULTCHARSET=GBK;Insert  intoT_demo_product (proid, Proname, Price)Values(1,'Product A','Ten'),(2,'Product B',' One'),(3,'Product C',' A'),(4,'Product D',' -'),(5,'Product e',' -');Insert  intoT_demo_operation (Opid, proid, Opcount)Values(1,1,2),(2,3,6),(3,3,1),(4,4,3),(5,7,3);

Internal connection, does not allow empty
SELECT * from T_demo_product A, t_demo_operation b where a.proid = b.proid;
SELECT * from T_demo_product a joins t_demo_operation b on a.proid = b.proid;

Left JOIN, to T_demo_product-based, if the corresponding existence of multiple records are recorded more than one, none is empty
SELECT * FROM T_demo_product a LEFT join t_demo_operation b on a.proid = b.proid;

Right connection, to t_demo_operation-based, if the corresponding to more than one record, no is empty
SELECT * from T_demo_product a right joins t_demo_operation b on a.proid = b.proid;

MySQL internal connection, left join, right connection

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.