Update rows in Table A from values of Table B in MySQL

Filed Under (General) by Wenbert on 14-02-2008

Tagged Under :

Sometimes, we need to update values of tables from the values from another table. Here is an example:

  1.  
  2.         UPDATE `transactions` t , `tran_daily` daily
  3.         SET
  4.             t.col_manager   = daily.Col_manager,
  5.             t.invoice_date  = daily.Invoice_date,
  6.             t.due_date      = daily.Due_date,
  7.             t.po_no         = daily.Po_no,
  8.             t.remark        = daily.Remark,
  9.             t.gross_amount  = daily.Gross_amount,
  10.             t.adjustments   = daily.Adjustments,
  11.             t.open_amount   = daily.Open_amount,
  12.             t.bill_to       = daily.Bill_to
  13.  
  14.         WHERE
  15.             t.company       = daily.Company AND
  16.             t.trans_type    = daily.Trans_type AND
  17.             t.invoice_no    = daily.Invoice_no AND
  18.             t.line_no       = daily.Line_no

Leave a Reply