I have written the following query using CTE in Postgres. Now I am unable to delete records from it.
WITH cte AS (
SELECT
firstname,
lastname,
country,
ROW_NUMBER() OVER (
PARTITION BY
firstname,
lastname,
country
) row_num
FROM
employee
)
DELETE FROM cte
WHERE row_num >1
When I run this query it shows me an error:
relation "cte" does not exist
Here is a sample of my table employee:
| id | firstname | lastname | country |
|---|---|---|---|
| 1 | Raj | Gupta | India |
| 2 | Raj | Gupta | India |
| 3 | Mohan | Kumar | USA |
| 4 | James | Barry | UK |
| 5 | James | Barry | UK |
| 6 | James | Barry | UK |