NYCPHP Meetup

NYPHP.org

[nycphp-talk] mySQL: update table from another table

Adam Maccabee Trachtenberg adam at trachtenberg.com
Thu Oct 30 15:55:03 EST 2003


I think by expr1 the manual means 'adam' or MD5('password') not a
SELECT.

-adam

On Thu, 30 Oct 2003, Brian Pang wrote:

> 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 ?
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>

-- 
adam at trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!



More information about the talk mailing list