i want to delete all rows from a table EXCEPT top 10 (order by view_count) SELECT * FROM table ORDER BY view_count LIMIT 10 so now i need a query that delete all other table which r not selected by above query tnx in advance
can you give the primary key column name? It should look something like DELETE FROM `table` WHERE `primary_key_name` NOT IN (SELECT `primary_key_name` FROM `table` LIMIT 10) Code (markup):
there's no primary key actually only two fields. id name & view_count i think its all about `view_count` & that query is not working...showing error
In that case you will need to create a primary key in the table with an auto increment value to distinguish each row. Otherwise you run the risk of it deleting rows you don't want it to