我要檢查一些不需要的記錄,並刪除它,下面的查詢MySQL不能指定目標表更新在FROM子句
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)
結構
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;
我的錯誤,我已經使用 MySQL說:文檔
1093 - 你不能指定目標表'包含'在FROM子句中更新
請幫我修正這個錯誤
儲備關鍵字使用反引號,比如'contain' –
請檢查該http://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in -from-clause – Ninja
Ya修改其實它在本地機器上工作在服務器上它拋出的錯誤 – raj