From: | "Bee(dot)Lists" <bee(dot)lists(at)gmail(dot)com> |
---|---|
To: | Submit Postgresql Novice <pgsql-novice(at)postgresql(dot)org> |
Subject: | Outer Right Join? |
Date: | 2020-02-20 08:04:59 |
Message-ID: | 8BE08FFD-68C7-45D9-979D-8249AC502BD3@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
I’m looking for a three-table join. The SQL that I have isn’t working.
companies table - list of companies
products table - list of products sold by those companies
contracts table - list of companies that hold ad contracts
I need to ask:
"Show me the queried product (i.e.: Screwdriver) listings with their company names that DO NOT have contracts"
SELECT DISTINCT ON ("listings"."product")
"listings"."product", "companies"."name"
FROM "listings"
RIGHT OUTER JOIN "contracts" ON ("contracts"."companyid" = "listings"."companyid")
LEFT JOIN "companies" ON ("companies"."scid" = "listings"."companyid")
WHERE (("listings"."product" ILIKE '%screwdriver%' ESCAPE '\'))
The result works without the RIGHT OUTER JOIN in there. When the RIGHT OUTER JOIN is in there, I get a hitlist of zero. Currently I have no contracts in that table, so those two queries should be the same. They are not.
To repeat, I want any company’s products that are in the contracts table, to not show up. “products with no contract”.
Any inside as to how I can get this to work, appreciated.
Cheers, Bee
From | Date | Subject | |
---|---|---|---|
Next Message | Mark Wallace | 2020-02-20 16:06:22 | Re: Outer Right Join? |
Previous Message | barry kimelman | 2020-02-17 16:42:09 | Re: Can't delete postgresql table record using Perl |