I have to check some unwanted records and remove it for that i have used below query
delete from contain_tab
where org_id = "RTY"
AND id_contain
NOT IN (
select id_contain from(
SELECT id_contain FROM contain_tab c
WHERE org_id = "RTY"
AND (c.cu_date,c.cv_date)
in(
select max(cu_date),max(cv_date) from contain_tab cs
where org_id = "RTY"
AND cs.container = c.container
and cs.mfest_id = c.mfest_id
and cs.sl_number = c.sl_number)
)
as id_contain)
Structure
CREATE TABLE `contain_tab` (
`id_contain` int(11) NOT NULL,
`org_id` varchar(5) NOT NULL,
`container` varchar(24) DEFAULT NULL,
`eta_dest` date DEFAULT NULL,
`mfest_id` varchar(30) DEFAULT NULL,
`sl_number` varchar(30) DEFAULT NULL,
`orig_id` varchar(8) DEFAULT NULL,
`cu_date` date DEFAULT NULL,
`cv_date` date DEFAULT NULL,
`vehicle` varchar(32) DEFAULT NULL,
`user_defined_field1` varchar(35) DEFAULT NULL,
`user_defined_field2` varchar(35) DEFAULT NULL
`created_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I got error MySQL said: Documentation
1093 - You can't specify target table 'contain' for update in FROM clause
Please help me to fix the error