嵌套查询

来源:互联网 发布:php向数据库中添加数据 编辑:程序博客网 时间:2024/05/22 12:11

1 基本子查询
语法

select 列名1 ... from 表名where 列名 比较运算符 (select命令)例如:select * from product where price > (select AVG(price) from product);

2 多个返回值的子查询
对于像比较运算符这些只要求单一值的比较运算符时,子查询的结果也必须是返回单一值的。而如果使用了in、not in这些要求返回多个运算符时,子查询的结果是可以返回多个值的。例如:

select name,address from user where uid not in (select uid from order_basic where odate='2010-10-1');

3 子查询与EXISTS运算符
例如:

select name,address from user where exists (select * from order_basic where user.uid = order_basic.uid);
0 0
原创粉丝点击