This is a discussion on combining updates on different tables? within the MySQL Database forums, part of the Database Forums category; Say I have the following two UPDATEs: UPDATE table1 SET a = 1 WHERE b = 1 UPDATE table2 SET c = 1 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On Jan 29, 10:38 am, "yawnmoth" <terra1...@yahoo.com> wrote: > Say I have the following two UPDATEs: > > UPDATE table1 SET a = 1 WHERE b = 1 > UPDATE table2 SET c = 1 WHERE d = 1 > > Is there a way to combine that into one SQL query, or is two the best > I'm going to be able to do? You can have multi-table updates, but in this particular case, where clauses are distinct. So, if you do an 'and' or 'or' on the where clauses, there will be cases where this will not work. The statement would be something like: update table1, table2 set table1.a = 1, table2.c = 1 where table1.b = 1 or table2.d = 1; As you can see, using 'or' or 'and' will impact both tables, instead of just 1. I am not SQL guru, so I am not sure if this is something that can be tricked into the where clause. -cheers, Manish |