Extend inner join to fetch not yet connected rows also - Mailing list pgsql-general

From Arup Rakshit
Subject Extend inner join to fetch not yet connected rows also
Date
Msg-id 7B8CBECF-09A5-492B-9E22-EDD7B0DBD469@zeit.io
Whole thread Raw
Responses Re: Extend inner join to fetch not yet connected rows also
List pgsql-general
I have craftsmanships table which has (id, name) and users table (id, email, ..). When a user has some craftsmanships,
theyare stored inside the contractor_skills(user_id, craftsmanship_id, id) table. 

What I want here is that to list all the available craftsmanships with id, name and has column. I can get now only
thosecraftsmanships that a specific user has,  

SELECT
    craftsmanships.id,
    craftsmanships.name,
    TRUE as has
FROM
    "craftsmanships"
    INNER JOIN "contractor_skills" ON "contractor_skills"."craftsmanship_id" = "craftsmanships"."id"
    INNER JOIN "users" ON "users"."id" = "contractor_skills"."user_id"
WHERE (contractor_skills.user_id = 8)
ORDER BY
    "craftsmanships".”id"

——————
 id |  name   | has
----+---------+-----
  1 | paint   | t
  2 | drywall | t
(2 rows)

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? 



Thanks,

Arup Rakshit
ar@zeit.io






pgsql-general by date:

Previous
From: Andrew Gierth
Date:
Subject: Re: Use of ?get diagnostics'?
Next
From: Jan Kohnert
Date:
Subject: Re: Extend inner join to fetch not yet connected rows also