Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

db2 query insert from another table

Tags:

db2

I have a table product(id_product , name );

I have another one: productHistory (id_H , id_product , name);

I wanna create a query (db2) to insert all the rows of product in productHistory;

I have a sequence product_history_seq

I wanna do something like that:

insert into productHistory 
        (id_h ,  , id_product , name) 
  values ( product_history_seq.nextval,..

Or,

select (id_product , name) from product

What's the correct query?

like image 786
senior Avatar asked Aug 02 '13 06:08

senior


Video Answer


1 Answers

I believe you are looking for:

insert into  productHistory 
       ( id_h
       , id_product 
       , name
       ) 
  select next value for product_history_seq
       , id_product 
       , name 
    from product 
;
like image 125
WarrenT Avatar answered Sep 29 '22 09:09

WarrenT