Delete with join on the same table and limit clause
I have a MySql table like this,
Session_Id Subscriber_Id Status
-------------------------------
abc 1234 Started
bcd 1235 Started
bcd 1235 Finished
And I need to delete rows with status 'Started' only if followed by a
'Finished'. This is a huge table, so I would be deleting 1000 records at a
time.
I read up a few similar threads, Multiple-table DELETE LIMIT, DELETE FROM
`table` AS `alias` ... WHERE `alias`.`column` ... why syntax error?
and tried the below queries,
mysql> delete a.* from FSESSION as a, FSESSION as b where
a.status='Started' and b.status='Finished' and a.session_id=b.session_id
limit 1000;
ERROR 1064 (42000): 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 'limit 1000' at line 1 ----> If I remove 'limit' this works
mysql> DELETE FROM v USING `FSESSION` AS v WHERE status = 'Started' and
exists(select 0 from FSESSION t where t.status='Finished' and
v.session_id=t.session_id) limit 1000;
ERROR 1064 (42000): 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 'limit 1000' at line 1 ---->
Does'nt work even when limit is removed.
I use MySql version 5.1.56-ndb-7.1.15. Please suggest a way to do this.
Thanks!
No comments:
Post a Comment