简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM