views:

77

answers:

2

data:

id1,id2
1    3
1    8
1    10
1    11
2    3
2    10
2    11
3    2
3    18
3    20
4    3
4    8
5    3
5    10
5    11
5    40
5    45
5    50
6    1
6    59
6    70

I won't get all id1 with id2 = 3,10,11.

For example, id1=4 only with id2=3, should not return.

The results should be

id1
1
2
5
+1  A: 

SQL code

SELECT ID1,COUNT(ID2) FROM TBTEST 
WHERE ID2 IN(3,10,11) 
GROUP BY ID1 
HAVING COUNT(ID2)=3

Is this what you need?

ZA
The grouping is not necessary, because every occurence of ID2 = 3 occurs only one time per ID1.
furtelwart
+2  A: 
SELECT distinct(ID1) FROM TBTEST WHERE ID2 IN(3,10,11)
Haim Evgi
Sorry. For example, id1=4 only with id2=3, should not return.
ZA