Reputation: 1554
I am trying to run a query that will delete all of the entries in a database except the 9 most recent entries. The uid is id_lv and the table is called last_viewed
mysql_query('DELETE FROM last_viewed WHERE id_lv NOT IN (SELECT id_lv FROM last_viewed ORDER BY id_lv, desc LIMIT 0, 9');
I get no errors at all but nothing happens.
Thanks
Upvotes: 0
Views: 342
Reputation: 9580
mysql_query('DELETE FROM last_viewed
WHERE id_lv NOT IN
(SELECT id_lv FROM last_viewed
ORDER BY id_lv desc LIMIT 0, 9)');
Upvotes: 1
Reputation: 107826
Bracketing error. You were missing a closing )
in the subquery and there shouldn't be a comma before the DESC keyword.
mysql_query('DELETE FROM last_viewed
WHERE id_lv NOT IN (
SELECT id_lv
FROM last_viewed
ORDER BY id_lv desc
LIMIT 0, 9)');
Upvotes: 0