SQL 二张表数据复制语句

1. sql 子查询应用

 

 

 

UPDATE hj_cy_jws u
set yyid = (
            SELECT hj.yyid 
            FROM hj_cy_jws jw JOIN hj_cy hj ON jw.grid = hj.grid 
            WHERE u.id = jw.id
            )

 

 

UPDATE hj_cy_jws u
set yyid = (
            SELECT DISTINCT hj.yyid 
            FROM hj_cy_jws jw JOIN hj_cy hj ON jw.grid = hj.grid 
            WHERE u.grid = hj.grid
            )
WHERE EXISTS (
              SELECT * FROM hj_cy_jws jw JOIN hj_cy hj ON jw.grid = hj.grid
              WHERE u.grid = hj.grid
              )

你可能感兴趣的:(sql)