PostgreSQL where all in array

后端 未结 9 1590
情书的邮戳
情书的邮戳 2020-11-30 07:23

What is the easiest and fastest way to achieve a clause where all elements in an array must be matched - not only one when using IN? After all it should behave

9条回答
  •  余生分开走
    2020-11-30 08:09

    create a mapping table with all possible values and use this

    select 
        t1.col from conversations_users as t1 
        inner join mapping_table as map on t1.user_id=map.user_id
    group by 
        t1.col  
    having  
        count(distinct conversations_users.user_id)=
        (select count(distinct user_id) from mapping)
    

提交回复
热议问题