mysql - Update multiple rows from results from a SELECT query to the same table -


i'm trying figure out how combine these 2 queries.

select `o`.`order_id` `orders` `o` join `customerdetails` `cd` on `cd`.`customer_id` = `o`.`customer_id` `o`.`orderplaceservertime` >= '2013-06-01 00:00:00' , `o`.`orderplaceservertime` <= '2013-06-31 23:59:59' , `cd`.`salesrep_id` = 6 

this gives me list of order_ids need update salesrep_id = 6 above query.

after list of order_ids query above use...

update orders set salesrep_id =  '6'  (order_id = 541304 or  order_id = 541597 or  order_id = 542318) 

doing updates orders correct salesrep_id.

ultimately i'd combine these make 1 query change salesrep_id

a solution proper update syntax join mysql

update orders o join customerdetails d      on d.customer_id = o.customer_id    set o.salesrep_id = 6  o.orderplaceservertime >= '2013-06-01 00:00:00'    , o.orderplaceservertime <= '2013-06-31 23:59:59'    , d.salesrep_id = 6 

here sqlfiddle demo


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -