PostgreSQL query returning multiple rows based on identifier

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

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

Do I have to scroll through each identifier and execute a query for each iteration?

+4
source share
2 answers
 select * from table where id in (1, 2, 3) 
+5
source

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

Do you really want to get results where id = 1 or id = 2 or id = 3

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

Or do you want to get results where id between 1 and 3

+5
source

Source: https://habr.com/ru/post/1499004/


All Articles