Answer the question
In order to leave comments, you need to log in
How to select records from the table if they do not exist (you need to select products for which some property is not filled)?
There are three tables:
options
product_options
products
The options table has fields:
id, key, name
The product_options table has fields:
product_id, key, value
The products table has fields:
id, name, image, url
I need to select all products that have the manufacturer property is not filled.
The problem is that if it is not filled, then there is simply no record in the table.
And if there is no entry, how can I select products?
I tried to be smart with LEFT JOIN, but it didn't work. Nothing is returned.
Here is my code:
SELECT po.value as value, o.name as name
FROM options o
LEFT JOIN product_options po ON (po.key = o.key)
LEFT JOIN products p ON (p.id = po.product_id)
WHERE po.value IS NULL
AND po.key = 'manufacturer'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question