我希望执行一个查询,如果存在(真或假),则返回一个 id 列表,而不是仅返回一个。
常见的存在查询如下
select exist(select 1 from one_table where id_table = 'some_value') 
我想要一个检查多个值的查询。会像下一个一样
select exist(select 1 from one_table 
             where id_table in('some_value_1', '...')) 
但在这种情况下,我正在寻找的所有 Id 都必须存在。
一种方法使用count(*):
select <n> = (select count(*) from one_table where id_table in ('some_value_1', '...')
该值<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
        . . .
       )
| 归档时间: | 
 | 
| 查看次数: | 6080 次 | 
| 最近记录: |