Reputation: 3
I have following query, that's not working.
select * from table where id in (
1,2, (select id from another_table)
)
How i can rewrite it?
Upvotes: 0
Views: 53
Reputation: 158
select * from table where id in (
select 1 from dual
union all
select 2 from dual
union all
select id from another_table);
I'm using union because this is faster than using an OR clause which also can be used.
Upvotes: 0
Reputation: 13924
select *
from table
where id in (1,2) OR id in(
select id from another_table
)
Upvotes: 1
Reputation: 11921
How about
select * from table
where id in (1,2)
or id in (select id from another_table)
Take care and use parentheses when adding additional WHERE
-conditions using and
!!!
Upvotes: 2
Reputation: 3230
select * from table where id in (
select 1 as id from dual
union all
select 2 as id from dual
union all
select id from another_table
)
Upvotes: 0