Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iC5ws-0004im-MQ for pgsql-general@arkaria.postgresql.org; Sun, 22 Sep 2019 17:47:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iC5vr-0003te-UK for pgsql-general@arkaria.postgresql.org; Sun, 22 Sep 2019 17:45:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iC5vr-0003tL-DO for pgsql-general@lists.postgresql.org; Sun, 22 Sep 2019 17:45:59 +0000 Received: from jan-kohnert.de ([2001:4ba0:fff1:c3::1]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iC5vk-0000pD-81 for pgsql-general@lists.postgresql.org; Sun, 22 Sep 2019 17:45:58 +0000 X-Virus-Scanned: amavisd-new at jan-kohnert.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jan-kohnert.de; s=20191; t=1569174348; bh=e28Wsk2Ziv0iZ55q0q+ioZmmBbxmlwiHNMGdu3H77kE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=zIfKVU6rSQ3v8xZWHYzVNzezP/m497NKcrEoY1VlngB0CCGq98yq6p9x6IrWQbNJ1 mKYbo8s3Y/XtrIJFTJ6hqxkqHtwzoFgX17yofGOVN6b11VL3hq3nyikBjhF3wZ0FeB GX4vRq0FICUGdA+uIMjvACS+V1402x4WstCLSZ1CJaQ3F987ztiQVuEChkqHJeJZ/A Re4ZJOtMbqeCX9SlplBGy5aeAdzoecI8mwkwGkLqQLqKpRfMjGhTew0g7GAFCGUJ6c e6SMEWGZpkbM6c+qwRK9IW42ESS+34w6h6y9Dgndrd7yHgI4FcI4D8AcyA+G5fU0bV wYz5MH+0bJWMQ== Received: from kohni-mobil.localnet (p4FD8BDB7.dip0.t-ipconnect.de [79.216.189.183]) by b079.blue.fastwebserver.de (Postfix) with ESMTPSA id ABD13400AFED1 for ; Sun, 22 Sep 2019 19:45:47 +0200 (CEST) From: Jan Kohnert 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> 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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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_skil= ls > table holds that relationship. I don=E2=80=99t think distinct is the corr= ect 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=20 relationship between user_id and craftmanship_id, that is true. =20 > 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=20 "contractor_skills"."craftsmanship_id" =3D > "craftsmanships"."id" LEFT JOIN "users" ON "users"."id" =3D > "contractor_skills"."user_id" WHERE (contractor_skills.user_id =3D 8 > OR contractor_skills.user_id IS NULL) > ORDER BY > "craftsmanships"."id=E2=80=9D; BUT: you don't use any of users' columns in select, where, or order by. And= =20 since users is in a left join it is just a table which is neither used nor= =20 relevant in that particular statement. In the end, it depends on how data is structured in your database and what = you=20 want to achieve. =2D-=20 MfG Jan