S
S
Steve2021-06-17 10:43:32
PostgreSQL
Steve, 2021-06-17 10:43:32

Why does it show 2 identical entries?

Displays three entries, but two are the same

SELECT 
               :projection, 
               "user".firstname || ' ' || "user".lastname AS created_by,
               "campaign_status".name as status 
            FROM campaign
            LEFT JOIN :user "user" ON campaign.user_id="user".id
            LEFT JOIN :campaign_status "campaign_status" ON campaign.campaign_status_id="campaign_status".id
            LEFT JOIN user_group "user_group" ON "user".id = "user_group".user_id
            WHERE 
              "user_group".group_id = $groupId 
              AND (campaign.search @> '{"tags_in": [$tagId]}' AND not(campaign.search @> '{"contacts_out": [$contactId]}'))
              OR (campaign.search @> '{"contacts_in": [$contactId]}')
            GROUP BY campaign.id, "user".id, "campaign_status".id
            ORDER BY :sortBy :orderBy
            LIMIT $limit OFFSET ($page - 1) * $limit


Why might this happen?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Steve, 2021-06-17
@CenterJoin

I just passed a collection with tags and imploded it, then checked with IN().
As a result, the request turned out like this IN ('[10]','[20] и т.д.)and completely satisfied my task

M
Melkij, 2021-06-17
@melkij

Because it matches your data?
If it's not clear, simulate an elementary nested loop on your fingers, reading from your tables one at a time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question