Hi all,
I am trying to do a select + insert in a single query and the syntax I think is pretty straight forward:
Insert into table1 (id,name)
select * from table2
Assuming similar data types in both tables this should work. The problem I have is, that in table 2 I do not want all names returned, but only distinct ones. So clearly, I'm wont get 'one' id from table 2.
Consider a case where table 2 had multiple rows called 'John', I'm ok with any of the IDs of these johns getting returned with the distinct name of john.
In case the above is not possible, Is there a way to generate timstamp based primary keys in DB2? Since I'll be doing batch inserts, microsecond precision might not work (which I tried using bigint(current_timestamp) and failed). I can only work with bigints as primary keys.
the main reason I'm trying to do this in a single SQL is to avoid the millions of rows clogging up my java memory if the select and inserts are separated.
Any help would be appreciated.
regards