[nycphp-talk] mySQL: update table from another table
Brian Pang
bpang at bpang.com
Thu Oct 30 15:51:03 EST 2003
Thanks, but this gives me an error
UPDATE table2 SET table2.field = SELECT table1.field FROM table1 WHERE
table1.id = table2.id
"You have an error in your SQL syntax near 'SELECT ....."
even though this fits the pattern of:
UPDATE tbl_name SET col_name1=expr1
> Brian,
>
> Here's an excerpt from the MySQL Manual 3.22
>
> " * Updates and deletes that run over multiple tables is
> harder to do
> in MySQL. This will, however, be fixed in MySQL 4.0
> with multi-table
> `DELETE' and multi-table `UPDATE' and in MySQL 4.1 with
> subselects. "
>
> And:
>
> ============================
> `UPDATE' Syntax
> ---------------
>
> UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
> SET col_name1=expr1, [col_name2=expr2, ...]
> [WHERE where_definition]
> [LIMIT #]
[snipped]
> I need to update table2 with data from table1
>
> the mysql4 code would be:
> update table2,table1 set table2.field = table1.field where
> table2.id = table1.id
>
> how is this done in mysql 3.x ?
More information about the talk
mailing list