php - Update a table sales with values from table products with WHERE clause in both Update and select query
My aim is to get values from table products to table sales where sales.Product= products.Productname. This works well. with the code below .
UPDATE sales
SET Amount=(SELECT Selling_Price FROM products WHERE sales.Product= products.Productname);
;
My challenge now is how to update only where sales.Amount= 0. While running this code. I want Column Amount with values ' != 0 ignored .
Answer
Solution:
Just add a
where
clause:Answer
Solution:
If you only want to update rows where
amount = 0
, then you would addwhere
clause to theupdate
:If
Amount
could beNULL
and you want those rows updated as well, you would asOR Amount IS NULL
.