• 0

SQL Query Help


Question

Hello,

 

I have a SQL question.

 

Let say that I have two tables.

 

id

--

1

2

3

 

 

sid id type
---  -- ------
1    1  1

2    2  1

3    3  1

4    1  2

5    2  2

6    1  3

 

I am trying to get returned t1.id, where t2.type = 1 and t2.type is not in ('2', '3')

From the example showed previously, only t1.id that would be returned is '3'.

 

 

Sorry for the bad explanation but I don't know how to explain it better.

 

Thanks for the heklpo

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0
select t1.id from t1 ,t2
where t1.id=t2.id
and t2.type=1
and t2.type not in (2,3)

The "not in" clause is redundant  as it is essentially the same as the "=1" clause.

This returns id's of 1,2 and 3.

So given the criteria returning only an id =1 is not possible

Link to comment
Share on other sites

This topic is now closed to further replies.