Bluehost.com Web Hosting $6.95

combining updates on different tables?

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 ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-29-2007
yawnmoth
 
Posts: n/a
Default combining updates on different tables?

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?

Reply With Quote
  #2 (permalink)  
Old 01-29-2007
Manish Pandit
 
Posts: n/a
Default Re: combining updates on different tables?



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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:08 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0