...
Detect templates with duplicated items
SELECT "ID" as tempalte_id, "IMPORT_TYPE", "NAME" as template_name, "CHECKLIST_ID" as "CHECKLIST_ID" FROM "AO_C2A220_TEMPLATE" acat
WHERE "CHECKLIST_ID" IN (
SELECT sub."CHECKLIST_ID"
FROM ( SELECT "CHECKLIST_ID", "VALUE", COUNT("VALUE") AS count_values
FROM "AO_C2A220_ITEM" acai
GROUP BY "CHECKLIST_ID", "VALUE"
) AS sub
GROUP BY sub."CHECKLIST_ID"
HAVING COUNT(sub."VALUE") = SUM(sub.count_values) / 2 );
Delete item details. The checklist ids can be found in the result of the first query.
delete from "AO_C2A220_QUOTE" where "ITEM_ID" in (
select min from( SELECT MIN("ID"),"CHECKLIST_ID", "VALUE", COUNT("VALUE") AS count_values
FROM "AO_C2A220_ITEM" acai
GROUP BY "CHECKLIST_ID", "VALUE"
having COUNT("VALUE") > 1
-- and "CHECKLIST_ID" = 11 -- ADD THIS CONDITION ALSO TO delete checklist by checklist, not all at once ) as abc
) ;
where for"CHECKLIST_ID" = 11
replace 11 with the value from the first queryDelete item assignee. The checklist ids can be found in the result of the first query.
delete from "AO_C2A220_ASSIGNEE" where "ITEM_ID" in (
select min from( SELECT MIN("ID"),"CHECKLIST_ID", "VALUE", COUNT("VALUE") AS count_values
FROM "AO_C2A220_ITEM" acai
GROUP BY "CHECKLIST_ID", "VALUE"
having COUNT("VALUE") > 1
-- and "CHECKLIST_ID" = 11 -- ADD THIS CONDITION ALSO TO delete checklist by checklist, not all at once ) as abc
) ;
where for"CHECKLIST_ID" = 11
replace 11 with the value from the first query
Delete linked items - needed only for Linked templates that are imported to the issues (IMPORT_TYPE - LINKED). The checklist ids can be found in the result of the first query.Status colour Yellow title Optional delete from "AO_C2A220_LINKED_ITEM" where "ITEM_ID" in (
select min from( SELECT MIN("ID"),"CHECKLIST_ID", "VALUE", COUNT("VALUE") AS count_values
FROM "AO_C2A220_ITEM" acai
GROUP BY "CHECKLIST_ID", "VALUE"
having COUNT("VALUE") > 1
-- and "CHECKLIST_ID" = 11 -- ADD THIS CONDITION ALSO TO delete checklist by checklist, not all at once ) as abc
) ;
where for"CHECKLIST_ID" = 11
replace 11 with the value from the first queryDelete duplicate items. The checklist ids can be found in the result of the first query.
delete from "AO_C2A220_ITEM" where "ID" IN(
select min from(
SELECT MIN("ID"),"CHECKLIST_ID", "VALUE", COUNT("VALUE") AS count_values
FROM "AO_C2A220_ITEM" acai
GROUP BY "CHECKLIST_ID", "VALUE"
having COUNT("VALUE") > 1
-- and "CHECKLIST_ID" = 11 -- ADD THIS CONDITION ALSO TO delete checklist by checklist, not all at once ) as abc
);
where for"CHECKLIST_ID" = 11
replace 11 with the value from the first queryRepeat steps 2, 3, and 4 (using
"CHECKLIST_ID" = your value)
as many times as there were templates found in the first query
...