David Villa
David Villa

Reputation: 3

How can I insert multiple entries into a table with a select?

INSERT INTO DM_SPONSOR_EQUIPO_VENTA dsev (dsev.SEV_IDEQUIPO_VENTA, dsev.SEV_IDSPONSOR)
VALUES (:id,
        (SELECT ds.SPO_IDSPONSOR  
         FROM DM_SPONSOR ds
         INNER JOIN DM_GRUPO dg ON ds.GP_IDGRUPO = dg.GP_IDGRUPO
         WHERE dg.GP_IDGRUPO = :idg))

Where :id is static and the second row is a multiple data inputs that the select returns?

Column A Column B
1 5600
1 83000

Upvotes: 0

Views: 37

Answers (1)

Littlefoot
Littlefoot

Reputation: 142720

Should be

insert into dm_sponsor_equipo_venta (column_a, column_b)
select :id, ds.spo_idsponsor
from dm_sponsor ds inner join dm_grupo dg on ds.gp_idgrupo = dg.gp_idgrupo
where dg.gp_idgrupo = :idg;

Upvotes: 3

Related Questions