也可以叫跨表查询,多表查询

select * from teacher tea, student stu;

内联接

select users.name, cars.car_name from users inner join cars on users.id = cars.pid order by users.id, cars.id;

JOIN ... ON ...

on后面只写主外键约束,其他的写在 where 后面,还有的话再加 and

外连接

左连接:

左表中查出全部数据,右表中只查出满足条件的数据

select * from users left join cars on users.id = cars.pid order by users.id, cars.id;

右连接:

右表中查出全部数据,左表中只查出满足条件的数据

select * from users right join cars on users.id = cars.pid order by users.id, cars.id;

自然连接

natural join