with col as ( select collection_id from harvested_collection hc where oai_source ='https://cris.une.edu.pe/server/oai/perucris' ),item as( select item_id from cwf_workflowitem cw where collection_id in(select * from col) union select item_id from collection2item cw where collection_id in(select * from col) ),rel as ( select right_id from item a left join relationship b on a.item_id =b.left_id union select left_id from item a left join relationship b on a.item_id =b.right_id )select * into itemParaBorrar from item union select * from rel delete from metadatavalue m where dspace_object_id in(select * from itemParaBorrar) delete from relationship r where left_id in(select * from itemParaBorrar) or right_id in(select * from itemParaBorrar) delete from harvested_item hi where item_id in(select * from itemParaBorrar) delete from collection2item ci where item_id in(select * from itemParaBorrar) delete from cwf_pooltask where workflowitem_id in( select workflowitem_id from cwf_workflowitem cw where item_id in(select * from itemParaBorrar) ) delete from cwf_claimtask where workflowitem_id in( select workflowitem_id from cwf_workflowitem cw where item_id in(select * from itemParaBorrar) ) delete from cwf_in_progress_user where workflowitem_id in( select workflowitem_id from cwf_workflowitem cw where item_id in(select * from itemParaBorrar) ) delete from cwf_workflowitem cw where item_id in(select * from itemParaBorrar) delete from item2bundle cw where item_id in(select * from itemParaBorrar) delete from item m where uuid in(select * from itemParaBorrar)