ALTER TABLE `BRANCHES`
ADD COLUMN `MODERATORS_GROUP_ID` bigint(20) DEFAULT NULL;

ALTER TABLE `BRANCHES`
ADD CONSTRAINT `FK_MODERATORS_GROUP_ID`
    FOREIGN KEY (`MODERATORS_GROUP_ID`)
    REFERENCES `GROUPS` (`GROUP_ID`);

UPDATE `BRANCHES`
SET `MODERATORS_GROUP_ID` = `BRANCH_ID`
WHERE EXISTS (
    SELECT * FROM `GROUPS`
    WHERE `GROUP_ID` = `BRANCH_ID`
);
