Check out example codes for "update having mysql". It will help you in understanding the concepts better.

Code Example 1

UPDATE contacts_domains cd, 
 (SELECT id FROM contacts_domains GROUP BY domain_id
   HAVING COUNT(contact_id) = 1) AS cdtmp
SET cd.dominant = 1
WHERE cd.id = cdtmp.id

Learn ReactJs, React Native from akashmittal.com