I need a query to delete all the duplicate records but just to keep one latest record based on valid_until
date column. I tried with the below but it says An expression of non-boolean type specified in a context where a condition is expected, near ','.
DELETE FROM tableOne
WHERE (id, valid_until ) NOT IN (
SELECT id, MAX(valid_until )
FROM tableOne
GROUP BY id
)
2条答案
按热度按时间fcy6dtqo1#
You can use an updatable CTE.
SQL Fiddle
dwbf0jvd2#
You can use
left join
and a conditionis null
to match the ones that are not the latests :