开发者

mysql column data copy from one table to another with a join?

开发者 https://www.devze.com 2022-12-09 20:27 出处:网络
Having trouble figuring out the syntax for this one... :-/ Table 1 IDFEEFAIFOE 0Fee1Fai1Foe1 1Fee2Fai2Foe2

Having trouble figuring out the syntax for this one... :-/

Table 1

ID  FEE   FAI   FOE
0   Fee1  Fai1  Foe1
1   Fee2  Fai2  Foe2
2   Fee3  Fai3  Foe3

Table 2

ID  FEE   FAI   FUM
 -  Fee1  Fai1  Fum1
 -  Fee2  Fai2  Fum2
 -  Fee3  Fai3  Fum3

Based on the shared columns FEE and FAI, which when combined form unique pairs, I'd like to copy the appropriate ID values from table 1 to table 2.开发者_StackOverflow社区 Not all data in table 1 is present in table 2 and vice versa, so the IDs have to be matched to their correct rows.

I know this requires an UPDATE SET and possibly a JOIN, but am having trouble coming up with anything that phpMyAdmin is willing to chew on, and having trouble finding a sufficiently related question on SO that can get me moving.

Sorry for such an easy one, and thank you for your time.


update table2
  join table1
    on (table1.FEE, table1.FAI) = (table2.FEE, table2.FAI)
   set table2.id = table1.id
0

精彩评论

暂无评论...
验证码 换一张
取 消