Search Postgresql Archives

Extend inner join to fetch not yet connected rows also

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

What I want here is that to list all the available craftsmanships with id, name and has column. I can get now only those craftsmanships 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@xxxxxxx









[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux