-1

I have available_quantity column in mobiles table and available quantity is 2. And I have quantity in stock table. This quantity is 7.

Now what is the SQL command for updating the available_quantity column? Means after updating available_quantity have to show 9.

DimaSan
  • 12,264
  • 11
  • 65
  • 75
  • Please tag your question with the database you are using. And edit your question and provide sample data and desired results. The question does not have enough information for an answer. – Gordon Linoff Sep 25 '16 at 11:50
  • Did you try anything. Search for `Update with Join` in google you will get the answer – Pரதீப் Sep 25 '16 at 11:51

1 Answers1

0


Hi,
You can use MERGE statement for updating table from another table,

MERGE INTO mobiles_table M
USING stock_table S
    ON (M.primary_key_column = S.primary_key_column)
    WHEN MATCHED THEN 
    UPDATE SET
M.quantity = M.quantity+S.quantity;

Edit appropriate table and column names in the query

Jim Macaulay
  • 4,709
  • 4
  • 28
  • 53