Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oQ1Iw-0002gr-MR for pgsql-sql@arkaria.postgresql.org; Mon, 22 Aug 2022 06:52:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oQ1Iu-0008SJ-Fe for pgsql-sql@arkaria.postgresql.org; Mon, 22 Aug 2022 06:52:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oQ1Iu-0008SA-2a for pgsql-sql@lists.postgresql.org; Mon, 22 Aug 2022 06:52:56 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oQ1Is-0004M9-0N for pgsql-sql@lists.postgresql.org; Mon, 22 Aug 2022 06:52:55 +0000 Received: by mail-io1-xd35.google.com with SMTP id h78so7556091iof.13 for ; Sun, 21 Aug 2022 23:52:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=famille-andre-be.20210112.gappssmtp.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc; bh=0Xu9vO8jPSmMGxjP0Ci795NVKvzyuuNRdMqC2QoLRGw=; b=VOkWD7eOOzWdOkXfExKP5kPF1tIwHJaAbDzNFvSThSUXFbTioWqnadd4ZyTJrWViL1 bISDOhy54a7yrbkYb6bT767boAIijTlQenO12FrYczhOH9zKEiKii6LEQ9IXQOuL0C2v qA8jxXEIz9HvELN9Phci0vnE9prNbP6/puPAboQAeHa/zTcEYnaYzMUnKdsBRdjVcjva safUHldhdkfRD/QxfzQqcq95oZfC7LWofBBPzNV0zYiyD20iB/ypWgUhUid6mwK0kPml i4q+/0zWtPdhVBMVG6ZZbPiiAnhVSUiZPdWchMe9xwwLQaQsXem6D8NDqZcjDm8Uhebr vSbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc; bh=0Xu9vO8jPSmMGxjP0Ci795NVKvzyuuNRdMqC2QoLRGw=; b=S/ORXhQhtdErUna4eED0qWpanVSUa4wJ1OCbmIwoT7uos471iZdrSTQtZNEPlpSmWr ilaFnl7QDng3RjRQjkC68LKUbDiW8CZb/O/z3cQH4BRt4LHQfZinT8LqDqQVr7PMsNbq H8V68V/qEAEfJ1cZWiqeCzQ0Hafd0FdPU0i8AkUq6hWoPtjU15nIoSjYSrstURA420uC AOmolBq5ysQrYrpeNqR+zT8sxXpw0fyBqi2mWuT2FgBVja2B0y2f9OFI1SmnvJ/YOY61 +7zKUFYmRGkysidE43gPdR1+BhGg5qg+rzD9NsCQPFnJu4xzcFEKXQBPRexzeCUr2hj3 yvNA== X-Gm-Message-State: ACgBeo1f+oNqtcnOurOHIWcajrrmDpN8RWijDVUtwmsi6oEtwcvtiK0P 5/nifXGXc+Lwjyeqqj8JfFV7sebWdsCKe5IODRkxiKq5OiyXIw== X-Google-Smtp-Source: AA6agR712Wp4ekLzF+oNMqlCQKx43yydpBvKrs+GEsUCp4mfgllI5HyIotg4qgwqIXx2XFdw95TfbFgZSpHzDiAZoLE= X-Received: by 2002:a05:6638:4804:b0:349:9bfe:80ea with SMTP id cp4-20020a056638480400b003499bfe80eamr5915695jab.66.1661151171982; Sun, 21 Aug 2022 23:52:51 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?B?QnJpY2UgQW5kcsOp?= Date: Mon, 22 Aug 2022 08:52:41 +0200 Message-ID: Subject: Most efficient way to select events from users having common subscriptions To: pgsql-sql@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000864a6505e6cee593" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000864a6505e6cee593 Content-Type: text/plain; charset="UTF-8" Hello, I have a project on which users may be registered to different challenges. And I would want to implement a "news" panel, where users are notified of events performed by other users, which have at least one challenge in common. My DB schema has tables like follows : - table "user" - user_id - etc. - table "challenge" - challenge_id - etc. - table "user_challenge_association" - user_id - challenge_id - team_id - table "activity" - user_id I would thus want to perform a request returning all activities of all users which have at least one entry in "user_challenge_association" where "challenge_id" is the same as another entry in "user_challenge_association" associated to the user for which I am doing the request. Imagine "user" contains (user_1, user_2, user_3), imaging "challenge" contains (challenge_1, challenge_2), imagine that user_1 is only registered to challenge_1 user_2 is only registered to challenge_2, and user_3 is registered to both challenges, I would want : - that request for user_1 only returns activities of user_3 - that request for user_2 only returns activities of user_3 - that request for user_3 returns activities of user_1 and user_2 What would be the best way to perform such a query ? Additional question : How could I integrate in the result a column indicating if, in all existing challenges, the resulting activity is linked to a user that was at least once in the same team as the user for which we perform the request ? (team information is in "user_challenge_association" table Many thanks for your advices, Brice --000000000000864a6505e6cee593 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

I have a project on which users = may be registered to different challenges. And I would want to implement a = "news" panel, where users are notified of events performed by oth= er users, which have at least one challenge in common.

=
My DB schema has tables like follows :
  • table &q= uot;user"
    • user_id
    • etc.
  • table "ch= allenge"
    • challenge_id
    • etc.
  • table &quo= t;user_challenge_association"
    • user_id
    • challenge_id=
    • team_id
  • table "activity"
    • user_i= d
I would thus want to perform a request returning all a= ctivities of all users which have at least one entry in "user_challeng= e_association" where "challenge_id" is the same as another e= ntry in "user_challenge_association" associated to the user for w= hich I am doing the request.

Imagine "user&qu= ot; contains (user_1, user_2, user_3), imaging "challenge" contai= ns (challenge_1, challenge_2), imagine that user_1 is only registered to ch= allenge_1 user_2 is only registered to challenge_2, and user_3 is registere= d to both challenges, I would want :
  • that request fo= r user_1 only returns activities of user_3
  • that request for user_2 = only returns activities of user_3
  • that request for user_3 returns a= ctivities of user_1 and user_2
What would be the best way to = perform such a query ?

Additional question : How c= ould I integrate in the result a column indicating if, in all existing chal= lenges, the resulting activity is linked to a user that was at least once i= n the same team as the user for which we perform the request ? (team inform= ation is in "user_challenge_association" table

Many thanks for your advices,
Brice
<= /div> --000000000000864a6505e6cee593--