2017-04-12 46 views
1

共同的價值我有一個表像這樣需要幫助的SQL查詢來發現行

+----+------+------+ 
| id | col1 | col2 | 
+----+------+------+  
| 1 | A | B |  
| 2 | B | D |  
+----+------+------+ 

現在我的用戶將與AD搜索。我想給共同的AD。什麼應該是查詢?

這裏常見的是B

+0

https://stackoverflow.com/help/how-to-ask - 什麼是你預期的結果? –

+0

我的預期結果是B.我已經提到過。 –

回答

0

對於你的榜樣,你可以這樣做:

select t1.col2 
from t t1 join 
    t t2 
    on t1.col2 = t2.col1 
where t1.col1 = 'A' and t2.col2 = 'D'; 
+0

謝謝!有用! –