0

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 CTE

SQL 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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tomas Am
  • 433
  • 4
  • 13

0 Answers0