あるテーブルの行を、別のテーブルの***列が等しい(user_id)という条件で更新します。
両方のテーブルには user_id
カラムがあります。 user_id列が等しい場合、
t2から
t1`にデータを挿入する必要があります。
ご協力ありがとうございました。
update
table1 t1
set
(
t1.column1,
t1.column2
) = (
select
t2.column1,
t2.column2
from
table2 t2
where
t2.column1 = t1.column1
)
where exists (
select
null
from
table2 t2
where
t2.column1 = t1.column1
);
あるいはこれ(t2.column1 <=> t1.column1 が多対一で、そのうちの誰でもいい場合)。
update
table1 t1
set
(
t1.column1,
t1.column2
) = (
select
t2.column1,
t2.column2
from
table2 t2
where
t2.column1 = t1.column1
and
rownum = 1
)
where exists (
select
null
from
table2 t2
where
t2.column1 = t1.column1
);
重複したuser_id'を作成しても構わない場合を除き、レコードがt1に既に存在する(user_idが一致する)場合は、挿入ではありません。
更新したいのでは?
UPDATE t1
SET <t1.col_list> = (SELECT <t2.col_list>
FROM t2
WHERE t2.user_id = t1.user_id)
WHERE EXISTS
(SELECT 1
FROM t2
WHERE t1.user_id = t2.user_id);
お役に立てるといいのですが・・・。