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 1iC1Hz-0000F6-Gz for pgsql-general@arkaria.postgresql.org; Sun, 22 Sep 2019 12:48:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iC1Hx-00071K-2H for pgsql-general@arkaria.postgresql.org; Sun, 22 Sep 2019 12:48:29 +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 1iC1Hw-00070X-Gx for pgsql-general@lists.postgresql.org; Sun, 22 Sep 2019 12:48:28 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iC1Ht-0008BX-Cf for pgsql-general@lists.postgresql.org; Sun, 22 Sep 2019 12:48:27 +0000 Received: by mail-pl1-x62d.google.com with SMTP id f19so5224403plr.3 for ; Sun, 22 Sep 2019 05:48:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zeit-io.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=bO4UJzZS462eUh6aFsu+yvj8hmcncuSAFwIbymvKhSg=; b=RHMQf3CTHBKR2PfpxvfL34WPairHj7eGf6/aLs+IuTLXgEKTBjK+nkUO28hv1cOgJr RYE6nTnBZg58Si3zIzorgkbKqxvOtVT3Tic3OiFTiDpiT3gJGat0m3/LtWK36KOQjrgM gwnJEaKWvpkBgN3uDzY8EJoafE5gOaEB8fqjqP/BtJM7Gn6zai5KmE7mkxGWI5eo+Aoy 3AJIIYia/41Veqm9aGml40qMhhVioAZ285q3BfEYxaBOujo4AckRGFN2HMjd+wU/InfH N/hA3EGu+D8/vVy3fM3oEerUK1UzZ5kiQOlGI6f65uFOqNQPeL2ROG13YFUM3wASPiAx cHQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=bO4UJzZS462eUh6aFsu+yvj8hmcncuSAFwIbymvKhSg=; b=BI2KkhU1+HmMSoBua68u7YWN19w9tt1n8tnwHLEdSXadJfG7JPBDrH9dLOio9l5xpW eEwrjSe9XgyxhWkmnuCYVWeE1m0HQ0hduOLtq74xpkS1P7n5/Yoa40+RWHWiydoi0ImO YwobyyxordQ0pyIcFEB1W1LtGdBqlXRlk+8By3nn5yl36O9hA7iwqd3WA+Z/iiyRsukj UJulyOgujyT0VqEuD7mKdwhS+9/i+3IfM7iJg8oaw7lBJmPmmaFW/dLcDBwHwvfe9c91 QmWD7Esm1rk3xJSM64Pcl+RVQN4Pu6W7CyRdU7y1SsgYYGdE80pvn3lkvKtm91cPVfK5 A7LA== X-Gm-Message-State: APjAAAW6F3nF/AEB+Z3vO2Fk9VKqGSdFJAZidsXzVlDyTkuRPxOm99c1 upKHuGFm+pvfFjlAEtSMDO64qHWT2Jo= X-Google-Smtp-Source: APXvYqyegud5HbJ7vvTP1g12WEPITqNJMzi62+ahw+hXfkWQDrq3FgoMuVfyQixSJl2mHlGF5Yqjdw== X-Received: by 2002:a17:902:968d:: with SMTP id n13mr15016551plp.263.1569156504214; Sun, 22 Sep 2019 05:48:24 -0700 (PDT) Received: from [192.168.0.102] ([45.123.160.163]) by smtp.gmail.com with ESMTPSA id y7sm6512838pfn.142.2019.09.22.05.48.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Sep 2019 05:48:23 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: Extend inner join to fetch not yet connected rows also From: Arup Rakshit In-Reply-To: <1780284.qfRisySgFs@kohni-mobil> Date: Sun, 22 Sep 2019 18:18:20 +0530 Cc: pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <7B8CBECF-09A5-492B-9E22-EDD7B0DBD469@zeit.io> <1780284.qfRisySgFs@kohni-mobil> To: Jan Kohnert X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Jan, > On 22-Sep-2019, at 5:38 PM, Jan Kohnert = wrote: >=20 > Hey, >=20 > Am Sonntag, 22. September 2019, 13:21:46 CEST schrieb Arup Rakshit: >> I have craftsmanships table which has (id, name) and users table (id, = email, >> ..). When a user has some craftsmanships, they are stored inside the >> contractor_skills(user_id, craftsmanship_id, id) table. >=20 > [...] >=20 >> But I want to list all craftsmanships and has column should have `t` = when >> user_id #8 has it, else `f`. How can I extend this query? >=20 > maybe something like >=20 > select > c.id, > c.name, > case when cs.user_id =3D 8 then true else false end as has > from craftsmanships c > left join contractor_skills cs > on cs.craftsmanship_id =3D c.craftmanship_id; >=20 > --=20 > MfG Jan >=20 But this query fetched duplicate data: id | name | has ----+---------------------------------------+----- 2 | drywall | t 1 | paint | t 1 | paint | f 11 | landscaping | f 12 | electrical | f 10 | countertops | f 13 | plumbing | f 5 | flooring | f 8 | decks (displayed as decks and patios) | f 6 | basements | f 4 | kitchens | f 3 | bathrooms | f 14 | handyman | f 9 | windows (windows and doors) | f 7 | carpentry | f (15 rows) >=20