mysql: assigned calls to user based on parent account or lead

Select List of Calls to Update:

SELECT
*

FROM
calls
LEFT JOIN accounts ON calls.parent_id = accounts.id
LEFT JOIN leads ON calls.parent_id = leads.id

WHERE

(
accounts.assigned_user_id = '7077c616-4f2c-f966-d9b6-5581807bae86' OR
leads.assigned_user_id = '7077c616-4f2c-f966-d9b6-5581807bae86'

)

;

 

Update Query:

UPDATE
calls x
LEFT JOIN accounts y ON x.parent_id = y.id
LEFT JOIN leads z ON x.parent_id = z.id

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

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

 

 

 

 

 

 

 

 

 

 

Leave a Reply

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