子查询
单行子查询
查询’软开1431班‘学生信息(单行子查询)
单行子查询
mysql> select gno from t_group where gname='软开1431班';
+---------+
| gno |
+---------+
| RK1431 |
+---------+
1 row in set
mysql> select * from t_student where gno=( select gno from t_group where gname='软开1431班');
+------------+----------+--------+------------+---------+
| sno | sname | gender | birthday | gno |
+------------+----------+--------+------------+---------+
此处省略……
+------------+----------+--------+------------+---------+
19 rows in set
多行子查询 [NOT] IN
查询’刘德华‘所带班级学生信息
多行子查询
mysql> select * from t_student where gno in( select gno from t_group where gmentor='刘德华');
+------------+----------+--------+------------+---------+
| sno | sname | gender | birthday | gno |
+------------+----------+--------+------------+---------+
此处省略……
+------------+----------+--------+------------+---------+
37 rows in set