I am trying to write a simple correlated sub query that deletes all records for the selected members except the latest one.
DELETE FROM table1 p
WHERE member_id IN (1, 2,3)
AND create_dttm < (SELECT MAX(create_dttm)
FROM table1
WHERE member_id = p.member_id)
But I get an error message
Incorrect syntax near ‘p’.
I can easily write 3 queries to get the work done. But was curious to know what is going wrong here ? Could you please enlighten me how to write this query correctly ?
Thanks in advance
Try