union on the same table
问题 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 ID1 = 196 union select * from table where ID1 = 150 but that doesn't cover the ID2 requirement. How should I do that? 回答1: If I understood your question correctly then this should be the answer: select * from mytable where id2