Skip to content
Advertisement

Extracting the id of the products missing from the third table with the specified value in SQL

I have 3 tables:

products (id, category, …),

store_offers (product_id, offer_id, platform) – joining the products table with many tables with offers, e.g. ebay, amazon, etc.

ebay_offers (id, status, country, …).

I need to get the id of products (in addition with a specific category_id) that have no listings on ebay (ie not available in the ebay_offers table with the value “uk” for the country column).

I tried something like this unfortunately it doesn’t show me the correct values:

I can guess why the query does not generate results, but in this case I have no idea how to extract the data that interests me.

Advertisement

Answer

I recommend using not exists:

You can do this with left join. The issue is the country condition in the where clause. It requires a match — conflicting with the null comparison. The syntax for the NULL comparison is also off. So:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement