13

I am trying to figure out how I can select multiple rows from a table, based on the id column. Something like this:

select * from table where id=1 or id=2 or id=3

Should I loop through every id and perform a query for each iteration?

2 Answers 2

27
select *
from table
where id in (1, 2, 3)
Sign up to request clarification or add additional context in comments.

Comments

8

If you want to have results where id = 1 and results where id = 2 and results where id = 3, you have to use a different logic.

You actually want results where id = 1 or id = 2 or id = 3

Or you want results where id in (1, 2, 3)

Or you want results where id between 1 and 3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.