select * from students s left join classes c on s.c_id = c.id;
复制代码
说明:格式:select * from 表1 别名1 left join 表2 别名2 c on 表1.字段名1 = 表2.字段名2
2、右连接查询(right join)
查询条件的一种,以右表为主根据条件查询左表数据,如果根据条件查询左表数据不存在使用null值填充
以“students,classes”表为例:
使用右连接查询学生表与班级表
select * from students s right join classes c on s.c_id = c.id;
复制代码
说明:select * from 表1 别名1 right join 表2 别名2 on 表1.字段名1 = 表2.字段名2;