Alexey Smirnov
Alexey Smirnov

Reputation: 3

Oracle SQL Query IN

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

Answers (4)

user3406675
user3406675

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

phlogratos
phlogratos

Reputation: 13924

select * 
from table 
where id in (1,2) OR id in(
   select id from another_table
)

Upvotes: 1

piet.t
piet.t

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

KrazzyNefarious
KrazzyNefarious

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

Related Questions