我有一个案例,我需要在地址表中将一组字段匹配为唯一,但为此,在数据库上,我必须检测重复项,从数据库中删除它们并更新所有关联的外键。
我最终可能会进行多次查询:
但是,向流程发送信息的多个查询的问题在于它是大数据的问题。
为此我必须:
只要我接受了查询测试,我想出了这个想法:
SELECT `` FROM `Addresses` AS `Original`
WHERE
( UPDATE `A` SET `address_id` = `Original`.`id` WHERE `address_id` = `Duplicated`.`id` ) OR
( UPDATE `B` SET `address_id` = `Original`.`id` WHERE `address_id` = `Duplicated`.`id` ) OR
( UPDATE `C` SET `address_id` = `Original`.`id` WHERE `address_id` = `Duplicated`.`id` ) OR
( UPDATE `Addresses` SET `deleted` = true WHERE `id` = `Duplicated`.`id` )
INNER JOIN `Addresses` AS `Duplicated`
ON
`Original`.`id` < `Duplicated`.`id` AND
`Original`.`street_id` = `Duplicated`.`street_id` AND
`Original`.`city_id` = `Duplicated`.`city_id` AND
`Original`.`door_number` = `Duplicated`.`door_number` AND
`Original`.`floor` = `Duplicated`.`floor` AND
`Original`.`extra` = `Duplicated`.`extra`