Suppose a table with the following columns:
pri_id , item_id , comment , date
I want to have an SQL query that will delete any records for a specific item_id that is older than a given date, but only as long as item_id are more than 15 rows for this item_id .
This will be used to clear comment entries older than 1 year for items, but I still want to save at least 15 entries at any given time. Thus, if I had one comment for 10 years, it would never have been deleted, but if I had 100 comments in the last 5 days, I would save only the most recent 15 entries. These, of course, are arbitrary record numbers and dates for this example.
I would like to find a very general way to do this that will work in mysql, oracle, postgres, etc. I am using the phod adodb library to abstract the DB, so I would like it to work well with this if possible.
sql datetime
Matt p
source share