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 1iC1sG-0001Jo-Rp for pgsql-general@arkaria.postgresql.org; Sun, 22 Sep 2019 13:26:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iC1sE-0002Fe-EK for pgsql-general@arkaria.postgresql.org; Sun, 22 Sep 2019 13:25:58 +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 1iC1sE-0002F5-0j for pgsql-general@lists.postgresql.org; Sun, 22 Sep 2019 13:25:58 +0000 Received: from jan-kohnert.de ([62.141.42.79]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iC1s7-0008RX-3g for pgsql-general@lists.postgresql.org; Sun, 22 Sep 2019 13:25:56 +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=1569158748; bh=yO/qvSSYnmC4bpJoT1LLvi12IElOm/gsB3nXJhYLQL4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gJQozYXWuCZCJOWCMxEdItr+ZqFA4nw7b3yHxWtbsjI0/wPfeZ14PaiJM/nzRd9e5 p0vWVhjfDoZvghUlq0oxPCJIgJI0YMnOJYf0z7gM0cV4mp79QYjByXXVXStgqOeydB X3ox0jO9m+VuOeWyyim7UpT03U6/OaR/JOnePK12MIvhIhLPcX5mza/mH+U8PYuh84 S5W3Jq6mYx+7W1uDa2eP6b4uMkf3lda1gZPj846ZuWqiO83b9mk6vnaUNMRCYxrHzu RU01xSJabJMgq0uwbCd6yhca+m7BdXRLzSJWAzxQZfVBjP6EpwyK8GroB/SKe52INE XuFraD4cf4VEw== Received: from kohni-mobil.localnet (p4FD8BDB7.dip0.t-ipconnect.de [79.216.189.183]) by b079.blue.fastwebserver.de (Postfix) with ESMTPSA id 1C8CF400AFED2 for ; Sun, 22 Sep 2019 15:25: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 15:25:46 +0200 Message-ID: <1695753.vyHXCZFGd1@kohni-mobil> In-Reply-To: References: <7B8CBECF-09A5-492B-9E22-EDD7B0DBD469@zeit.io> <1780284.qfRisySgFs@kohni-mobil> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Arup, Am Sonntag, 22. September 2019, 14:48:20 CEST schrieb Arup Rakshit: > Hi Jan, > > > On 22-Sep-2019, at 5:38 PM, Jan Kohnert > > wrote: > > maybe something like > > > > select > > > > c.id, > > c.name, > > case when cs.user_id = 8 then true else false end as has > > > > from craftsmanships c > > left join contractor_skills cs > > > > on cs.craftsmanship_id = c.craftmanship_id; > > But this query fetched duplicate data: yeah, that's possible, since I don't exactly know your data model. If only the values above are required, you could simply use distinct: select distinct c.id, c.name, case when cs.user_id = 8 then true else false end as has from craftsmanships c left join contractor_skills cs on cs.craftsmanship_id = c.id order by c.id; -- MfG Jan