-2

I have two Tables and they are

Table Receiving

enter image description here

and Table GeneralInventory

enter image description here

My Question is How can I Insert the Data from Receiving To GeneralInventory if the data is not the same? or if it is same the update the column QtyPack Of generalinventory sum it up.

TYSM

fancyPants
  • 46,782
  • 31
  • 80
  • 91
Nyx Assasin
  • 131
  • 1
  • 9
  • Possible duplicate of [How to 'insert if not exists' in MySQL?](http://stackoverflow.com/questions/1361340/how-to-insert-if-not-exists-in-mysql) – Pred Aug 02 '16 at 11:43

1 Answers1

0

You can use INSERT ... ON DUPLICATE KEY UPDATE. For this you need a unique index or a primary key on your table, so that duplicates can be detected via index.

Then your query would be like this:

INSERT INTO GeneralInventory (ItemCode, QtyPack)
SELECT ItemCode, QtyPack
FROM Receiving
ON DUPLICATE KEY UPDATE
SET QtyPack = QtyPack + VALUES(QtyPack);
fancyPants
  • 46,782
  • 31
  • 80
  • 91