![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
I have two tables with identical structure (one is an old backup), and I'm trying to update a column in one table with content from another. Like so: UPDATE t1, t2 SET t1.comment = t2.comment WHERE t1.username = t2.username AND t1.postdate = t2.postdate If I understood the manual correctly, this SHOULD work, but the description in the manual was a little confusing to me so I'm not 100% sure. The logic is, update t1.comment with what's in t2.comment, if t1.username matches t2.username and t1.postdate matches t2.postdate. I was particularly confused about "UPDATE t1, t2". Why do I enter both tables, if I'm only reading t2 and updating t1? Indeed. I think that what that means is update (using t1, t2) set |
|
I tried running the query, but after about 30 minutes I had to stop it. Table t2 has about 285,000 rows in it, though, so I'm not sure if it should really take that long, or if I got caught in a loop or something. |
|
Am I correct in my understanding of this, or do you guys see a glaring error that I'm overlooking? |
|
TIA, Jason |
#3
| |||
| |||
|
|
I have two tables with identical structure (one is an old backup), and I'm trying to update a column in one table with content from another. Like so: UPDATE t1, t2 SET t1.comment = t2.comment WHERE t1.username = t2.username AND t1.postdate = t2.postdate If I understood the manual correctly, this SHOULD work, but the description in the manual was a little confusing to me so I'm not 100% sure. The logic is, update t1.comment with what's in t2.comment, if t1.username matches t2.username and t1.postdate matches t2.postdate. I was particularly confused about "UPDATE t1, t2". Why do I enter both tables, if I'm only reading t2 and updating t1? I tried running the query, but after about 30 minutes I had to stop it. Table t2 has about 285,000 rows in it, though, so I'm not sure if it should really take that long, or if I got caught in a loop or something. Am I correct in my understanding of this, or do you guys see a glaring error that I'm overlooking? TIA, Jason |
#4
| ||||
| ||||
|
|
I have two tables with identical structure (one is an old backup), and I'm trying to update a column in one table with content from another. Like so: UPDATE t1, t2 SET t1.comment = t2.comment WHERE t1.username = t2.username AND t1.postdate = t2.postdate |
|
If I understood the manual correctly, this SHOULD work, but the description in the manual was a little confusing to me so I'm not 100% sure. The logic is, update t1.comment with what's in t2.comment, if t1.username matches t2 .username and t1.postdate matches t2.postdate. |
|
I was particularly confused about "UPDATE t1, t2". Why do I enter both tabl es, if I'm only reading t2 and updating t1? |
|
I tried running the query, but after about 30 minutes I had to stop it. Tab le t2 has about 285,000 rows in it, though, so I'm not sure if it should re ally take that long, or if I got caught in a loop or something. |
#5
| |||
| |||
|
|
I have two tables with identical structure (one is an old backup), and I'm trying to update a column in one table with content from another. Like so: UPDATE t1, t2 SET t1.comment = t2.comment WHERE t1.username = t2.username AND t1.postdate = t2.postdate If I understood the manual correctly, this SHOULD work, but the description in the manual was a little confusing to me so I'm not 100% sure. The logic is, update t1.comment with what's in t2.comment, if t1.username matches t2.username and t1.postdate matches t2.postdate. I was particularly confused about "UPDATE t1, t2". Why do I enter both tables, if I'm only reading t2 and updating t1? |
|
I tried running the query, but after about 30 minutes I had to stop it. Table t2 has about 285,000 rows in it, though, so I'm not sure if it should really take that long, or if I got caught in a loop or something. |
#6
| |||
| |||
|
|
I have two tables with identical structure (one is an old backup), and I'm trying to update a column in one table with content from another. Like so: UPDATE t1, t2 SET t1.comment = t2.comment WHERE t1.username = t2.username AND t1.postdate = t2.postdate snip |
#7
| |||
| |||
|
|
On Tuesday, November 1, 2011 5:13:25 AM UTC-4, Jason C wrote: I have two tables with identical structure (one is an old backup), and I'm trying to update a column in one table with content from another. Like so: UPDATE t1, t2 SET t1.comment = t2.comment WHERE t1.username = t2.username AND t1.postdate = t2.postdate snip |
#8
| |||
| |||
|
|
On Tuesday, November 1, 2011 5:13:25 AM UTC-4, Jason C wrote: I have two tables with identical structure (one is an old backup), and I'm trying to update a column in one table with content from another. Like so: UPDATE t1, t2 SET t1.comment = t2.comment WHERE t1.username = t2.username AND t1.postdate = t2.postdate snip OK, let's get tricky with it now... In these tables, postdate is varchar(14). How can I modify the code to update if the username matches, and the first 13 characters match? I know that you can't use a REGEX with UPDATE (at least, that's my understanding), and I'm sure that I can do it with a PHP script. But can it be done with a direct query? |
![]() |
| Thread Tools | |
| Display Modes | |
| |