左连接:以左表为主

select a.*,b.* from a left join b on a.b_id = b.id;

 

右连接:以右表为主

select a.*,b.* from a right join b on a.b_id = b.id;

 

内连接:只列出两张表关联查询符合条件的记录

select a.*,b.* from a inner join b on a.b_id = b.id;

 

案例:

select c.id c_id,c.`name` c_name

from t_teacher t LEFT JOIN t_class c on t.id=c.t_id; #4条,以老师表为主

 

select c.id c_id,c.`name` c_name

from t_teacher t RIGHT JOIN t_class c on t.id=c.t_id; #4条,以班级表为主

 

select c.id c_id,c.`name` c_name

from t_teacher t INNER JOIN t_class c on t.id=c.t_id; #3条,只展示匹配条件的记录

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
  • 2021-07-23
猜你喜欢
  • 2021-08-18
  • 2022-01-09
  • 2022-12-23
  • 2022-02-09
相关资源
相似解决方案