If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Update 2 table that have joined via key

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-30-07, 09:31
bono56 bono56 is offline
Registered User
 
Join Date: May 2004
Posts: 133
Update 2 table that have joined via key

i have 2 table that have joied via a key, now i want to UPDATE fields in 2 table, is there any way for updating 2 joined table?
i can do this by IN synatx like this:
Code:
UPDATE table 2 SET blabla='yes'
WHERE id IN (SELECT id FROM table1)
but in thousands of record, it cause hangin.
Reply With Quote
  #2 (permalink)  
Old 05-30-07, 10:27
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
You're updating thousands of records at once with the same value???
Reply With Quote
  #3 (permalink)  
Old 05-30-07, 13:52
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
This would be faster from what I've read. Also note you should have the id columns indexed.

Code:
UPDATE table1, table2
SET table2.blabla='yes'
WHERE table1.id=table2.id
Reply With Quote
  #4 (permalink)  
Old 05-31-07, 03:52
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Just a quick question. If there is referential integrity here (which there ought to be as you have implied the use of a key between the two tables) then in which direction does this integrity run?

it is table1 has (many) table2
or table2 has (many) table1
?

From what I can see you are updating table2 based on the fact that it contains the same ID as an ID that exists in table1. However (and i'm only guessing here) when will table2 NOT have the an ID that exists in table1 if they share the same key???
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On