I think this should be pretty simple, but I’m a SQL newb.
I have two tables. One is a list of items IDs and descriptions, the other is a map of corresponding old and new IDs. Like this:
ID_MAP
OLD_ID NEW_ID
---------------
1 101
2 102
ITEMS
ID DESCRIPTION
--------------------
1 "ItemA"
2 "ItemB"
...
101 <null>
102 <null>
I need to copy the old item descriptions to the new items according to the map. I think I need to use an inner join inside of an update, but it’s not working and I’m not even sure that’s the right way to go.
I’m trying statements like
update ITEMS
set (select ITEMS.DESCRIPTION
from ITEMS
join ID_MAP
on ITEMS.ID = ID_MAP.NEW_ID) =
(select ITEMS.DESCRIPTION
from ITEMS
join ID_MAP
on ITEMS.ID = ID_MAP.OLD_ID)
But of course it’s not working. What should I be doing?
1 Answer