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 > How to update one table depending on another table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-18-08, 21:25
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
How to update one table depending on another table

Hello ALL,

I have the two tables;

Code:
t1
DocID  Word   TitleWord  
1         book      0
1         read       0
1         open       0

2         computer 0
2         book        0

3         paper       0
3         desk        0



t2
DocID   Word     Tag
1          book      noun

2          computer   noun
I would like to update the t1.TitleWord field according to the table t2.
Code:
t1
DocID  Word   TitleWord  
1         book      1
1         read       0
1         open       0

2         computer 1
2         book        0

3         paper       0
3         desk        0
I want to use the following statement
Code:
UPDATE t1, t2

  SET  
         t1.TitleWord = '1'
WHERE
       t1.DocID = t2.DocID  AND t1.Word = t2.Word
I wonder if this statement is correct.
Reply With Quote
  #2 (permalink)  
Old 12-19-08, 03:11
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
Quote:
Originally Posted by cy163
...I wonder if this statement is correct.
I dunno
why not try it and find out, and save the 6..12 hour delay?
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 12-19-08, 10:35
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
healdem, thanks.

I have tried with this statement and it worked well. However, I am not sure. Hence, i post it here to get comments.
Reply With Quote
  #4 (permalink)  
Old 12-19-08, 11:16
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
well if it works it works
or is the question
I've tried this, but is there a better solution?
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 01-04-09, 09:48
galih galih is offline
Registered User
 
Join Date: Feb 2008
Location: Bandung - Indonesia
Posts: 15
UPDATE t1
SET TitleWord=1
where DocID=1 AND Word="book"

UPDATE t1
SET TitleWord=1
where DocID=2 AND Word="computer"
__________________
Forum Informatika - Indonesian Informatics Online Community - http://if.web.id
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