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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -