I have a table that need to be migrate to new table.
Table A migrates to Table B
Table A
| ID | type |
| A1 | A |
| A2 | B |
| A3 | A |
| A4 | both |
| A5 | A |
and I hope the table B will look like this
Table B
| ID | FKA | TYPE |
| B1 | A1 | Aa |
| B2 | A2 | Bb |
| B3 | A3 | Aa |
| B4 | A4 | Aa |
| B5 | A4 | Bb |
| B6 | A5 | Aa |
If you realized that if type is both, it will insert two times in table B from table A.
**FKA is the foreign key from table A
Currently I do 3 queries
query 1:
insert into tableB
select sequence1.nextVal, ID,
(case
when type = 'A' then 'Aa'
when type = 'B' then 'Bb'
when type = 'both' then 'Aa'
else NULL
end
) from tableA
query 2
insert into tableB
select sequence1.nextVal, ID,
(case
when type = 'both' then 'Bb'
else 'laterdelete'
end
) from tableA
query 3
delete from tableB where type = 'laterdelete'
thanks guys