Update multiple rows from results from a SELECT query to the same table
I'm trying to figure out how to combine these two queries.
SELECT `o`.`Order_ID`
FROM `Orders` `o`
JOIN `CustomerDetails` `cd` ON `cd`.`Customer_ID` = `o`.`Customer_ID`
WHERE `o`.`OrderPlaceServerTime` >= '2013-06-01 00:00:00'
AND `o`.`OrderPlaceServerTime` <= '2013-06-31 23:59:59'
AND `cd`.`SalesRep_ID` = 6
This gives me a list of Order_IDs that I need to update with the
SalesRep_ID = 6 from the above Query.
After I get the list of Order_IDs from the Query above I use...
UPDATE Orders SET SalesRep_ID = '6'
WHERE (Order_ID = 541304
OR Order_ID = 541597
OR Order_ID = 542318)
Doing so updates the orders with the correct SalesRep_ID.
Ultimately I'd like to combine these to make one query where I would just
change the SalesRep_ID
No comments:
Post a Comment