inuShiva
inuShiva

Reputation: 173

Merging two MySQL Tables SQL Statement

I'm trying to "merge" two tables and have found a few examples but I'm having difficulty applying them as it continues to say I have syntax error:

UPDATE T2
SET payable_id = T1.payable_id, payable_type = T1.payable_type
FROM payments_distributions AS T2
JOIN payables AS T1
  ON T1.payments_distribution_id = T2.id

It mentions that the FROM is at an invalid position at the moment.

I'd appreciate the help. Thanks

Upvotes: 0

Views: 34

Answers (1)

sticky bit
sticky bit

Reputation: 37472

Move the SET clause to the end and all of the table references after UPDATE.

UPDATE payments_distributions t2
       INNER JOIN payables t1
                  ON t1.payments_distribution_id = t2.id
       SET t2.payable_id = t1.payable_id,
           t2.payable_type = t1.payable_type;

Upvotes: 3

Related Questions