-5

I have same title of products from different stores..lets say... Produt title= A from store= 1 product title = A from store = 2... If store= 1and s title=A only udate price..if store =2 and product =A insert as a new row.. (shouldnt give error of duplications because its from other store).. And if title isnt duplicate simply. Insert it

How to do this with insert query in MYSQL?

1 Answer 1

0
BEGIN TRAN

UPDATE tablename
SET price = yourprice
WHERE store = 1 and title = A

IF (@@ROWCOUNT = 0)
   INSERT tablename (title, store, price, productid)
VALUES (yourtitle, yourstore, yourprice, yourproductid)

COMMIT

I am unable to test the code, but I copied it from here. Let me know if it helps.

Sign up to request clarification or add additional context in comments.

4 Comments

If title is duplicate(same) store is different insert as a new row? And update if title is same store is same? And insert it simply if title isnt duplicate? How to do this
i did not get your comment. Can you explain? Also, why dont you look into if exists then update else insert quesries in mysql ?
I have same title of products from different stores..lets say... Produt title= A from store= 1 product title = A from store = 2... If store= 1and s title=A only udate price..if store =2 and product =A insert as a new row.. (shouldnt give error of duplications because its from other store).. And if title isnt duplicate simly. Insert it
i updated my answer. hope it helps.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.