I have this query
SELECT * FROM orders, products, suppliers WHERE product_id=products.id AND `geleverd` = 1 AND supplier_id=suppliers.id
It works fine except that when the suppliers_id is NULL it is not picking those up. I need that so when a supplier is filled it should get the supplier name and when it is NULL it should also get that line because further on in the code I have if supplier_id = NULL
place text
This is my suppliers database:
And this is my orders database:
So my query needs to show everything where geleverd is 1 no matter if supplier_id is NULL or not
Advertisement
Answer
When you also want information of suppliers when the supplier_id
is null
you just need to and an OR
condition.
Your query will then look like as follows:
SELECT * FROM orders, products, suppliers WHERE product_id=products.id AND `geleverd` = 1 AND (supplier_id=suppliers.id OR supplier_id IS NULL);