How to delete from table if count is greater than 20

Posted by joseph on Stack Overflow See other posts from Stack Overflow or by joseph
Published on 2010-05-26T04:57:05Z Indexed on 2010/05/26 5:01 UTC
Read the original article Hit count: 217

Filed under:

Hi, I have a mysql table that I need to only contain 20 newest records before adding additional records. New rows are added daily so I would like it first delete any records that are greater than the 20 allowed starting with the earliest.

The table contains an auto increment "id" column so I can easily determine which is the earliest records.

Thanks for any help.

© Stack Overflow or respective owner

Related posts about mysql