2017-04-12 42 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

谢谢!有用! –