mysql: assign opportunities to user based on parent account

Query to Select List:

 

SELECT
*

FROM
opportunities
LEFT JOIN accounts_opportunities ON accounts_opportunities.opportunity_id = opportunities.id
LEFT JOIN accounts ON accounts_opportunities.account_id = accounts.id

WHERE
accounts.assigned_user_id = '7077c616-4f2c-f966-d9b6-5581807bae86';

 

 

UPDATE Query:

UPDATE
opportunities x
LEFT JOIN accounts_opportunities y ON y.opportunity_id = x.id
LEFT JOIN accounts z ON y.account_id = z.id

SET x.assigned_user_id = '7077c616-4f2c-f966-d9b6-5581807bae86'

WHERE
z.assigned_user_id = '7077c616-4f2c-f966-d9b6-5581807bae86';

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *