-- Generate Non-Duplicated PARENT FOLDER List DROP TABLE DataInventory; CREATE TABLE DataInventory AS Select * from ( SELECT SERVER, Parent, REPLACE( Parent, "X:\","\\mpe.ca\datadrive\") AS UNCPath, REPLACE(REPLACE(Parent,("X:\" || Server),"/Shared/N-Data"),"\","/") AS EgnytePath, sum(FileCount) as FileCount, Sum(FileSize) as FileSize, 'Parent' as Source from FolderData Where Parent != ( SELECT Parent FROM DuplicateList ) GROUP by UNCPath ) UNION SELECT SERVER, Parent, REPLACE(PATH,"X:\","\\mpe.ca\datadrive\") AS UNCPath, REPLACE(REPLACE(PATH,("X:\" || Server),"/Shared/N-Data"),"\","/") AS EgnytePath, FileCount, FileSize, 'Project' as Source from FolderData Where FolderData.Project NOT in ( SELECT A.Project FROM DuplicateList as A) AND FolderData.Parent in ( Select B.Parent FROM DuplicateList as B ); delete FROM DataInventory where Parent in ( select Parent from DataInventory group by Parent HAVING count(*) > 1 ) and Source = 'Project';