子查询
子查询分为 标量子查询,列(级)子查询,行(级)子查询,表(级别)子查询,前两种较为常见
标量子查询
子查询返回单行单列
-- 查询年龄最大的学生信息
select * from student where age =
(select DISTINCT s.age from student s order by age desc LIMIT 1);
列(级)子查询
子查询返回一列多行
-- 查询选择了Java课程的学生信息
select * from student where sid in
(select sc.sid from score sc INNER JOIN course c on sc.cid=c.cid
where c.`name`='Java');
行(级)子查询
子查询返回一行多列,了解即可
-- 查询男生中年龄最大的学生信息
select *
from student
where (sex,age)=(select sex,age from student where sex='男' order by age desc limit 1)
-- 改用group by
select *
from