PostgreSQL where all in array

后端 未结 9 1580
情书的邮戳
情书的邮戳 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:13

    select id from conversations where not exists(
        select * from conversations_users cu 
        where cu.conversation_id=conversations.id 
        and cu.user_id not in(1,2,3)        
    )
    

    this can easily be made into a rails scope.

提交回复
热议问题