mysql - How to create sql query to insert values from another table? -
i have table related table 1:1. first table called 'deal' has: id, deal_ext_id fields sec table called 'deal_ext' has: id, externalid, systemid fields.
i have temp table contains externalid, systemid fields need inserted sec table (deal_ext).
because relation between both tables (deal, deal_ext) 1:1, foreign need updated when values inserted 'deal_ext' table.
how can have loop, getting through temp table , first insert new line 'deal_ext' new id, second, new id, update 'deal' table accordingly?
thanks!
phase 1: insert deal_ext(external_id) select t.campaign_id tempdeal t;
phase 2: update deal set deal_ext_id = (select e.id tempdeal t, deal_ext e t.campaign_id = e.external_id , t.deal_id = deal.id)
solved!
mysql sql
No comments:
Post a Comment