-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?

Farooq Ch
  • 1
  • 4

1 Answers1

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.

Community
  • 1
  • 1
Renuka Deshmukh
  • 998
  • 9
  • 16
  • 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 – Farooq Ch Mar 02 '16 at 23:35
  • i did not get your comment. Can you explain? Also, why dont you look into _if exists then update else insert_ quesries in mysql ? – Renuka Deshmukh Mar 02 '16 at 23:47
  • 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 – Farooq Ch Mar 03 '16 at 00:08
  • i updated my answer. hope it helps. – Renuka Deshmukh Mar 03 '16 at 00:19