2015-09-28 81 views
0

我有一個表格,例如列id_type和其他列num_area。我想搜索num_area的值與某個值不匹配的所有id_type。SQL:選擇該行的某一列與特定值不匹配的行

id_type num_area 
----  ---- 
1   121 
2   121 
1   95 
3   47 
4   65 

對於爲例,如果我想ID_TYPE不具備num_area 121,它將返回我,ID_TYPE 3和4

感謝

回答

3

計劃

  • list id_type其中num_area是121
  • li ST不同ID_TYPE不是位於上述

查詢

select distinct id_type 
from example 
where id_type not in 
(
    select id_type 
    from example 
    where num_area = 121 
) 
; 

輸出

+---------+ 
| id_type | 
+---------+ 
|  3 | 
|  4 | 
+---------+ 

sqlfiddle

0

試試這個查詢。我得到了沒有子查詢的結果。

SELECT DISTINCT(e1.id_type) 
FROM example e1 
JOIN example e2 ON(e1.id_type = e2.id_type AND e2.num_area != '121'); 
相關問題