Insert or update when product is present using mysql
Posted
by
Aryan
on Stack Overflow
See other posts from Stack Overflow
or by Aryan
Published on 2012-11-10T09:31:34Z
Indexed on
2012/11/10
11:01 UTC
Read the original article
Hit count: 154
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
© Stack Overflow or respective owner