zac
zac

Reputation: 4918

select specific records using IN

I need to select records that has ID = 10,23,30 so I wrote this SQL

Select * from mytable where position(id in '10,23,30') > 0 

But the problem I get additional records where ID = 1 and 2 Any ideas how to select only what I need ?

Upvotes: 1

Views: 72

Answers (2)

Roman Marusyk
Roman Marusyk

Reputation: 24609

Use IN operator:

Select * from mytable where id in (10,23,30)

Upvotes: 3

jarlh
jarlh

Reputation: 44795

No need for position, just do IN:

Select * from mytable
where id in (10,23,30) 

Upvotes: 6

Related Questions