Postgresql Query Returning Multiple Rows Based on Id

Postgresql Query Returning Multiple Rows Based on Id

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

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

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

Your Answer

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

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.