简体   繁体   中英

Update MYSQL table with values from other tables

I have the following tables:

tbl1:

CC  GG   GA   VALUE
01 NULL NULL  10
02 NULL NULL  22
01 NULL NULL  04
03 NULL NULL  04

tbl2:

CC GG GA
01 aa xx
02 bb yy
03 cc zz

How can I update table 1 GG and GA values from tbl 2, linking by CC?

Try :

UPDATE tbl1,tbl2
SET tbl1.GG = tbl2.GG, tbl1.GA = tbl2.GA
WHERE tbl1.CC = tbl2.CC

I think its pretty self explanatory - but it updates tbl1.GG to tbl2.GG and tbl1.GA to tbl2.GA where tbl1.CC equals tbl2.CC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM