我正在尝试根据某些文件删除重复的行.当我运行以下查询时:
delete from slowmo_vid as sv1, slowmo_vid as sv2 where sv1.video_id = '2luh6g3ni5ex' and sv1.slowmo_end_t<=sv2.slowmo_end_t;
我收到错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as sv1, slowmo_vid as sv2 where sv1.video_id = '2luh6g3ni5ex' and sv1.slowmo_end' at line 2
表的字段是:id,video_id internal_uri,slowmo_end_t
您似乎试图在DELETE
语句中进行ANSI-92样式的内部联接.但该WHERE
子句不能同时用于强制连接并对结果集强制执行限制.相反,请执行以下操作INNER JOIN
以删除所需的记录.请注意,很明显该WHERE
条款正在扮演什么角色.
更新:如果要删除除包含max的记录以外的所有记录,video_id
则可以在WHERE
子句中添加嵌套子查询.
DELETE sv1.* FROM slowmo_vid sv1 INNER JOIN slowmo_vid sv2 ON sv1.slowmo_end_t <= sv2.slowmo_end_t WHERE sv1.video_id = '2luh6g3ni5ex' AND sv1.video_id <> (SELECT x.id FROM (SELECT MAX(t.video_id) AS id FROM slowmo_vid t) x)