列子查询
create table stude
(
id int,
name varchar(10)
);
insert into stude values
(1,'张三'),
(2,'李四'),
(3,'王五');
--成绩表 只有及格的人
create table scores
(
stu_id int,
score int
);
insert into scores values
(1,80),
(2,90);
select *
from stude
where id in(
--列子查询 返回一列
select stu_id
from scores
);
SELECT *
FROM 学生表
WHERE 学生ID 在 (
子查询:查出所有有成绩的学生ID
)
————————————————————————————————————————————————
| 类型 | 返回结果 | 关键字 |
|---|---|---|
| 标量子查询 | 1 个值 | = |
| 列子查询 | 一列多个值 | IN |

浙公网安备 33010602011771号