Insert or update when product is present using mysql
- by Aryan
main_product table
productid outward shopid
333 2 44//present
343 4 44//present
353 5 44//present
363 1 44//present
373 2 44//not present
min_product table
productid outward shopid
333 1 44
343 1 44
353 1 44
363 1 44
SELECT DISTINCT (A.productid),A.outward, B.productid,B.outward FROM main_product A INNER JOIN min_product B on B.productid=A.product_id where A.shopid='44' and B.shopid='44'
my question how can i INSERT OR UPDATE in one query using mysql by checking if it is present or not
if present update else insert
something like this?
INSERT
INTO mytable (key, value)
VALUES ($newkey, $newvalue)
ON DUPLICATE KEY UPDATE
SET value = $newvalue