Reputation: 39
I have a table in SQL Server 2008 with columns serial, ida, idb
, and remark
.
Example data :
serial ida idb remark
1 3 4 null
2 3 6 null
3 3 7 null
4 2 3 null
5 4 7 null
6 4 6 null
I want to select the common idb
from ida
3 and 4. I am confused here how to write the SQL query for this.
A little help will be appreciated.
Upvotes: 0
Views: 2986
Reputation: 3522
SELECT t1.idb
FROM mytable AS t1, mytable AS t2
WHERE t1.ida = 3 AND t2.ida = 4 AND t1.idb = t2.idb
Upvotes: 2
Reputation: 7093
Select idb from mytable
Where ida = 3
intersect
Select idb from mytable
Where ida = 4
Upvotes: 1