简体   繁体   English

PostgreSQL查询根据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. 我试图找出如何根据id列从表中选择多行。 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? 我应该遍历每个id并为每次迭代执行查询吗?

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. 如果您希望结果为id = 1且结果为id = 2且结果为id = 3 ,则必须使用不同的逻辑。

You actually want results where id = 1 or id = 2 or id = 3 实际上你想要的结果是id = 1 or id = 2 or id = 3

Or you want results where id in (1, 2, 3) 或者你想要的结果,其中id in (1, 2, 3)

Or you want results where id between 1 and 3 或者你想要id between 1 and 3结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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