Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Update Query issue

I know it has something to do with the syntax, but I'm looking for a way to do the following:

UPDATE modules
SET ServerID = boards.ServerID
FROM boards,modules
WHERE modules.ID = boards.ID

this doesnt work. I'm using MySQL

like image 823
snoofkin Avatar asked Jun 15 '26 01:06

snoofkin


1 Answers

Try this:

UPDATE boards,modules
SET modules.ServerID = boards.ServerID
WHERE modules.ID = boards.ID

Read MYSQL UPDATE syntax at http://dev.mysql.com/doc/refman/5.0/en/update.html

You can also perform UPDATE operations covering multiple tables ....

UPDATE items,month SET items.price=month.price
WHERE items.id=month.id;

The preceding example shows an inner join that uses the comma operator, but multiple-table UPDATE statements can use any type of join permitted in SELECT statements, such as LEFT JOIN.

like image 87
Gajahlemu Avatar answered Jun 16 '26 16:06

Gajahlemu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!