如何检查是否存在 id 列表

Pau*_*Pau 2 sql postgresql

我希望执行一个查询,如果存在(真或假),则返回一个 id 列表,而不是仅返回一个。

常见的存在查询如下

select exist(select 1 from one_table where id_table = 'some_value') 
Run Code Online (Sandbox Code Playgroud)

我想要一个检查多个值的查询。会像下一个一样

select exist(select 1 from one_table 
             where id_table in('some_value_1', '...')) 
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,我正在寻找的所有 Id 都必须存在。

Gor*_*off 5

一种方法使用count(*)

select <n> = (select count(*) from one_table where id_table in ('some_value_1', '...')
Run Code Online (Sandbox Code Playgroud)

该值<n>是 id 的数量。

另一种方法是使用以下序列exists

select (exists (select 1 from one_table where id_table = id1) and
        exists (select 1 from one_table where id_table = id2) and
        . . .
       )
Run Code Online (Sandbox Code Playgroud)