A表
ID、NAME、AGE
B表
ID_CARD、NAME、AGE
我现在知道
A表ID=1
B表ID_CARD=431025
怎么吧B表的NAME、AGE赋值给A表
当前已知的两种方法,还有没有其他的办法,越全越好。
UPDATE
A a
SET
a.NAME = (SELECT NAME FROM B WHERE ID_CARD = 431025)
,a.AGE = (SELECT AGE FROM B WHERE ID_CARD = 431025)
WHERE
a.ID = 1;
UPDATE
a
SET
a.NAME = b.NAME
,a.AGE = b.AGE
FROM
A a
LEFT JOIN B b ON a.ID = (case when b.ID_CARD = 431025 then a.ID else a.ID+1 end)
WHERE
a.ID = 1;
UPDATE
A
SET
A.NAME = B.NAME
, A.AGE = B.AGE
FROM
A
INNER JOIN B ON A.ID = 1 AND B.ID_CARD = '431025';