1
DELETE i
FROM
data_positive AS p, 
incident AS i
WHERE p.id in (
SELECT max(id)
FROM data_positive
GROUP BY url
HAVING count(*) > 1)
AND p.id = i.data_positive_id

When I try above query to delete incident table, I get below error.

ERROR:  syntax error at or near "i"
LINE 1: delete i
               ^
********** Error **********

ERROR: syntax error at or near "i"
SQL state: 42601
Character: 8

I tried it with left outer JOIN also but I have same error. Whats wrong with the query?

Yavuz
  • 1,257
  • 1
  • 16
  • 32
  • 1
    Look at the second solution in the top voted answer to the duplicate, or at the documentation: http://www.postgresql.org/docs/current/static/sql-delete.html `using` is your friend here. – jpw Apr 01 '16 at 23:04
  • Actually I tried it before but with a comma after "data_positive AS p". Anyway it works now. – Yavuz Apr 01 '16 at 23:18

0 Answers0