I need to return all values for: select...where IN (1,2,3,3,3,1)
I have a table with unique IDs. I have the following query:
Select * From Table_1 Where ID IN (1,2,3,3,3,1);
So far I'm returning only 3 records for unique values (1,2,3)
I want to return 6 records.
I need to get result set shown on the picture.
You can do it. But not with IN.
Keep in mind if you want your dataset Ordered you have to supply the order by clause.
You can't do that with the
IN
operator. You can create a temporary table and JOIN:Another (maybe uglier) option is to do a
UNION
:You cannot do this using the
IN
condition, becauseIN
treats your items as a set (i.e. ensures uniqueness).You can produce the desired result by joining to a
UNION ALL
, like this: