I am trying to delete duplicates from many to many table via PGADMIN4 tool.
If I am selecting duplicates then the query works fine and returns all duplicates:
WITH CTE (organizationsid, manufacturerid, DuplicateCount) AS
(
SELECT
organizationsid,
manufacturerid,
ROW_NUMBER() OVER (PARTITION BY organizationsid, manufacturerid
ORDER BY organizationsid) AS DuplicateCount
FROM
public.manufacturerrelationships
)
SELECT *
FROM CTE
WHERE DuplicateCount > 1;
But if I am trying to replace SELECT *
with DELETE
at the end, I get this error:
ERROR: relation "cte" does not exist
LINE 12: FROM CTESQL state: 42P01
Character: 308
The table has only two columns referring to different tables. What is the reason of the error and how could I delete duplicates?