『1』带IN的子查询
employee表
department表
SELECT num,d_id,name,age,sex,homeaddr
FROM employee
Where d_id in (select d_id from department);
『2』带比较运算符的子查询
scholarship表
computer_stu表
SELECT id,name,score
FROM computer_stu
WHERE score>=(select score from scholarship where level=1);
『3』带EXISTS关键字的子查询
使用exists关键字时,内层查询语句不返回查询的记录。而是返回一个真假值。当返回true执行,返回flase不执行
employee & department表 见实例一
SELECT * FROM employee
WHERE EXISTS
(select d_name from department
where d_id=1003);
SELECT * FROM employee
WHERE EXISTS
(select d_name from department
where d_id=1004);
『4』带ANY关键字的子查询
computer_stu & scholarship表 见实例3
SELECT * FROM computer
WHERE score >=any (select score from scholarship);
『5』带ALL关键字的子查询
computer_stu & scholarship表同上
SELECT * FROM computer_stu
WHERE score >=all
(SELECT score FROM scholarship);