本篇文章主要介绍MySQL里的多表关联查询,其中包括了笛卡尔积查询、内连接查询、外连接查询、全连接查询,另外还会介绍复合条件查询和子查询。
一、笛卡尔积查询
1、首先创建表并插入数据
1)doctor表
--创建一个doctor表
create table doctor(
doc_id int auto_increment primary key not null,
doc_name varchar(50),
age int,
dept_id int
);
--给doctor插入数据
insert into doctor(doc_name,age,dept_id) values
('A',19,200),
('B',26,201),
('C',30,201),
('D',24,202),
('E',20,200),
('F',38,204)