Select like and unlike record pattern SQL

selectsqlite

Lets assume I got this table, that got file pathes :

id    file                
 1     /etc/file.txt      
 2     /etc/.delete.file.txt      
 3     /etc/secondfile.txt      
 4     /etc/four.txt      
 5     /etc/five.txt      
 6     /etc.delete.five.txt   

I want to get all the files that are not deleted,

So if there is a file : .delete.file.txt -> I don't want to select both .delete.file.txt and also file.txt (always the prefix is .deleted)

Expected result after query :

id    file                
 3     /etc/secondfile.txt      
 4     /etc/four.txt      

How can I do that?
(Using SQLITE)

Best Answer

Assuming that your file column is unique, you can do this:

SELECT
REPLACE(file, '.delete.', '') AS file
FROM your_table
GROUP BY REPLACE(file, '.delete.', '')
HAVING COUNT(*) = 1

You "delete" the ".delete." and then return only the rows that don't appear multiple times.