Multi-table query for MySQL

Source: Internet
Author: User

1. Cartesian product
select * from emp,dep; select * from emp,dep where emp.dep_id = dep.id;select * from emp,dep where emp.dep_id = dep.id and dep.name = "技术";
2, within the connection: only two tables have a corresponding record of the relationship
select * from emp inner join dep on emp.dep_id = dep.id;select * from emp inner join dep on emp.dep_id = dep.id                                                        where dep.name = "技术";        inner join 连接两个表, where过滤条件,只取条件符合的
3, left join: On the basis of the internal connection to retain the left table does not have a corresponding relationship record
select * from emp left join dep on emp.dep_id = dep.id;
4, right connection: On the basis of the internal connection to keep the right table does not have a corresponding relationship record
select * from emp right join dep on emp.dep_id = dep.id;
5, the full connection: On the basis of the internal connection to keep left, the right table does not correspond to the record
select * from emp left join dep on emp.dep_id = dep.idunionselect * from emp right join dep on emp.dep_id = dep.id;

Multi-table query for MySQL

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.