$check = "SELECT up.quantity AS stockAble,
oh.quantity AS stockAsk
FROM stock_update up
JOIN orders oh
ON up.quantity > oh.quantity
AND up.package = oh.product_id
WHERE oh.reference_no = 12345
AND up.location_id = 4
";
In the query, I select all the quantity of a package based on the reference no.
In the reference number of 12345, for instance, there are three rows of three products with each different quantity.
Stock Ask in oh.quantity From orders
+---------------+--------------+------------+
reference_no product_id quantity
+---------------+--------------+------------+
12345 1 30
12345 2 10
12345 3 20
However it needs to check if the quantity or the product which is asked is available in our table.
Stock Available in stock_update
+--------------+------------+
product_id quantity
+--------------+------------+
1 10
2 15
3 25
Based on the two tables above, there is one product which its available quantity is less than the quantity which is asked. It is in the row or in the product_id of 1
If the condition is so, then I want the query return nothing or false.
The query will return true if only all the product and the quantity which is asked is available.
How to do that in the query I have tried above? Thank you very much for the help.
>=instead of>nullakano row. except that you probably want to use>=instead of>