Table structure:
It is impossible to select entries with the maximum deletion date, which are grouped by the same code, with the condition that they are all deleted. If entries have the same code, but have different deletion statuses, then these entries should not be selected. In this example, you need to select records with id = 3, id = 4. I could only come up with such a query to the database:
SELECT * FROM analyzes_test WHERE code IN (SELECT code FROM analyzes_test GROUP BY code HAVING count(code)>1) AND deleted = (max deleted_date) But I do not know how to completely substitute the largest date of removal.

MAX(deleted_date)- Grundy(code, deleted) IN (SELECT code, max(deleted) FROM analyzes_test GROUP BY code HAVING count(code)>1)- Mike