UPDATE `customers` AS t1
LEFT JOIN (
SELECT
t2.`customer_id`,
COUNT(*) as cnt
FROM `contacts` AS t2
GROUP BY t2.`customer_id`
) AS t3
ON t1.`id` = t3.`customer_id`
SET t1.`count_contacts` = t3.`cnt`,
t1.`contacts_exists` = IF(t3.`cnt` > 0, 1, 0)