mysql有4种表连接关系:
-
内连接:只取两张表共同的部分(符合条件的部分)
#语法:左表 inner join 右表 on 判断条件 select * from employee inner join department on employee.id = department.id;
-
左连接:在内连接的基础上保留左表的记录
#语法:左表 left join 右表 on 判断条件 select * from employee left join department on employee.id = department.id;
-
右连接:在内连接的基础上保留右表的记录
#语法:左表 right join 右表 on 判断条件 select * from employee right join department on employee.id = department.id;
-
全连接:在内连接的基础上保留左右两表没有对应关系的记录
语法:左连接语法 union 右连接语法;select * from employee left join department on employee.id = department.id union select * from employee right join department on employee.id = department.id;