Manga Black Manga Black - 1 year ago 77
MySQL Question

Mysql delete from Rows 20 onwards

I have an


select * from table1 where member_id='$member_id' order by date_time_modified desc;

which returns 48 rows, but I only want to the use the first 20 results.

How can I use a single
statement to keep the first 20 rows and delete all of the rows after the 20th row (21 to 48).

Answer Source

You can use LIMIT in your delete query, just change your sort order to delete the last rows and not the firsts

FROM table1
WHERE member_id='$member_id'
ORDER BY date_time_modified ASC
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download