I MERGE records from newtest
to test
.
merge into test t
using newtest nt
on (t.id = nt.id)
when matched then
update
set t.name = nt.name
when not matched then
insert (id, name)values (nt.id, nt.name);
Those records in newtest
which are fit for on
conditions need be deleted.
Though i could do it with a delete
SQL, but i want to know can it be done in that MERGE sentence?
As kordiko clarified, you cannot delete from another table using the MERGE statement. You can accomplish the delete in a separate statement as below:
DELETE FROM newtest nt
WHERE NOT EXISTS
(SELECT 1 FROM test t where t.id = nt.id);
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.