关联查询

左关联(只要主表有的数据都会展示出来)

select * from tb_user u(主表) left join tb_class c (从表)on u.id=c.id;  通过id把两个表id相同的数据连接起来

 

中关联(后表没有的数据不会展示出来)

select * from tb_user u join tb_class c on u.id=c.id;  join相当于inner join

 

右关联(只要主表有的数据都会展示出来)

select * from tb_user u(从表) right join tb_class c (主表)on u.id=c.id;

 

内关联(只会把两表id相同的展示出来)

select * from tb_user u,tb_class c where u.id=c.id;

 

横连接(union、union all)

select * from tb_class c where id in (1,3)
union   会把多条数据去重连接起来

union all  不去重连接多条数据
select * from tb_class c where id in (2,3);

posted @ 2021-04-12 19:22  终末s  阅读(98)  评论(0)    收藏  举报