1) EXISTS ()括號裏只要有返回值就會執行 EXISTS 之前的語句
2) select 1 的問題
3) in查詢相當於多個or條件的疊加,這個比較好理解,比如下面的查詢
select * from user where userId in (1, 2, 3);
等效於
select * from user where userId = 1 or userId = 2 or userId = 3;
not in與in相反,如下
select * from user where userId not in (1, 2, 3);
等效於
select * from user where userId != 1 and userId != 2 and userId != 3;
總的來說,in查詢就是先將子查詢條件的記錄全都查出來,假設結果集爲B,共有m條記錄,然後在將子查詢條件的結果集分解成m個,再進行m次查詢
值得一提的是,in查詢的子條件返回結果必須只有一個字段,例如
select * from user where userId in (select id from B);
而不能是
select * from user where userId in (select id, age from B);
而exists就沒有這個限制
4) group by 加上limit 不能實現topN的需求
再用limit的時候所有的group by 都是一個組,只會取出全部的前幾條limit數據
5)要想實現order by 必須只能有一個reduceTask
只需要有reduce階段,並且reduceTask爲1