BIT_COUNT(HEX(:value1) ^ HEX(:value2))
UPDATE `address` AS `a1`
JOIN (
SELECT MIN(`id`) AS `id` FROM `address` GROUP BY `organizationfk`
) AS `a2` ON `a2`.`id` = `a1`.`id`
LEFT JOIN (
SELECT `organizationfk` FROM `address` WHERE `primary` = 1
) AS `a3` ON `a3`.`organizationfk` = `a1`.`organizationfk`
SET `a1`.`primary` = 1
WHERE `a3`.`organizationfk` IS NULL