Reputation: 190
am trying to insert a data via single query.
select seg_id from seg where product_id='177' and variant_id='527';
insert into main(main_id,main_name,segment_id) values('3333','4444','***')
I want to replace that *** and place selected seg_id.
Also,main_id,main_name will be taken from user along with product_id and variant_id while segment_id should be fetched from DB.
DB Structure:
Segment table:
segment_key(PK)
segment_id
product_id
variant_id
main table:
main_id
main_name
segment_id
creationdate
Upvotes: 0
Views: 33
Reputation: 1270371
Use insert . . . select
:
insert into main(main_id, main_name, segment_id)
select '3333', '4444', seg_id
from seg
where product_id = '177' and variant_id = '527';
Upvotes: 5