From: Jan Kohnert <nospam001-lists@jan-kohnert.de>
To: pgsql-general@lists.postgresql.org
Subject: Re: Extend inner join to fetch not yet connected rows also
Date: Sun, 22 Sep 2019 19:45:47 +0200
Message-ID: <9177656.fJROvCpnoI@kohni-mobil> (raw)
In-Reply-To: <5C7E04B7-F5E3-4F2C-99A7-A8842153F531@zeit.io>
References: <7B8CBECF-09A5-492B-9E22-EDD7B0DBD469@zeit.io>
<1695753.vyHXCZFGd1@kohni-mobil>
<5C7E04B7-F5E3-4F2C-99A7-A8842153F531@zeit.io>
Hi Arup,
Am Sonntag, 22. September 2019, 15:30:38 CEST schrieb Arup Rakshit:
> When someone adds a craftsmanship to their skill set, the contractor_skills
> table holds that relationship. I don’t think distinct is the correct tool,
> as it will eliminate the correct data. users and craftsmanship has m:n
> relationship via the join table contractor_skills.
depending on the definition of table "contractor_skills" it can give you a n:m
relationship between user_id and craftmanship_id, that is true.
> SELECT
> craftsmanships.id,
> craftsmanships.name,
> CASE WHEN contractor_skills.user_id IS NULL THEN
> FALSE
> ELSE
> TRUE
> END AS has
> FROM
> "craftsmanships"
> LEFT JOIN "contractor_skills" ON
"contractor_skills"."craftsmanship_id" =
> "craftsmanships"."id" LEFT JOIN "users" ON "users"."id" =
> "contractor_skills"."user_id" WHERE (contractor_skills.user_id = 8
> OR contractor_skills.user_id IS NULL)
> ORDER BY
> "craftsmanships"."id”;
BUT: you don't use any of users' columns in select, where, or order by. And
since users is in a left join it is just a table which is neither used nor
relevant in that particular statement.
In the end, it depends on how data is structured in your database and what you
want to achieve.
--
MfG Jan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: nospam001-lists@jan-kohnert.de
Subject: Re: Extend inner join to fetch not yet connected rows also
In-Reply-To: <9177656.fJROvCpnoI@kohni-mobil>
References: <7B8CBECF-09A5-492B-9E22-EDD7B0DBD469@zeit.io> <1695753.vyHXCZFGd1@kohni-mobil> <5C7E04B7-F5E3-4F2C-99A7-A8842153F531@zeit.io> <9177656.fJROvCpnoI@kohni-mobil>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox