如何在PostgreSQL中编写选择查询以遍历选择查询返回的数组

问题描述 投票:0回答:1
SELECT b_items_p_id FROM  public.box WHERE b_id =1

and this is what it returns

{1,3,5}

现在每个值,即1、3和5,我想运行另一个选择查询:

select p_desc from public.products where p_id = 1
sql arrays postgresql foreach nested-query
1个回答
0
投票

您可以使用box运算符加入productsany(),如下所示:

select p_desc 
from public.box b 
inner join public.products p on p.p_id = any(b.b_items_p_id)
where b.b_id =1
© www.soinside.com 2019 - 2024. All rights reserved.