1.
示例:
select customerid, amount
from orders
where amount = (select max(amount) from orders);
2.
子查询中使用的操作符:
* ANY
SELECT c1 FROM t1 WHERE c1 > ANY (SELECT c1 FROM t2);
Returns true if the comparison is true for any of the rows in the subquery.
* IN
SELECT c1 FROM t1
WHERE c1 IN
(SELECT c1 from t2);
* SOME
SELECT c1 FROM t1
WHERE c1 >
SOME (SELECT c1 FROM t2);!
* ALL
SELECT c1 FROM t1
WHERE c1 >
ALL (SELECT c1 from t2);
3.
exists 操作符
select isbn, title
from books
where not exists
(select * from order_items where order_items.isbn=books.isbn);
4.
行匹配
select c1, c2, c3
from t1
where (c1, c2, c3) in (select c1, c2, c3 from t2);
5.
用子查询生成一个暂时性表格
select * from
(select customerid, name from customers where city=Box Hill)
as box_hill_customers;
注意,子查询后面的as从句是必须的。