union on the same table

Posted by StupidDeveloper on Stack Overflow See other posts from Stack Overflow or by StupidDeveloper
Published on 2010-06-03T10:45:49Z Indexed on 2010/06/03 10:54 UTC
Read the original article Hit count: 331

Filed under:
|

I have a table:

ID | Id1 | Id2
1  | 100 | 12
2  | 196 | 140
3  | 196 | 141
4  | 150 | 140
5  | 150 | 199

I want to write a query that will give me a table containing records with the same ID2 and with id1 equal to 196 or 150. I thought about union:

select * from table where itemId = 196 union select * from table where itemId = 150

but that doesn't cover the ID2 requirement. How should I do that?

© Stack Overflow or respective owner

Related posts about sql

Related posts about union