Wednesday 15 June 2011

join - Delete all but X newest entries in two joined MySQL tables -


I am experimenting with a query that I will use for sorting two related mysql tables. I am using it to remove all of the most recent entries.

This query behaves properly as I think:

  SELECT O.id AS O_id, RT as T.id O Left join RT as object field custom values OID = T on TON as TNS Where the new modification is O.Disabled = 1 and O.CustomField = 58 and O.ObjectId = 202784 and T.ID (not the selection ID (for the objects containing the object ID 202784), I get the ObjectCustomField Value ID and transaction ID (Section ID Transaction from Where Field = 58 and Object ID = 202784 DESC LIMIT made by ORDER 5) Test   

For all but most recent 5 items.

How can I now convert it to a normal query that I can manually run on all rows instead of specifying ObjectId?

In short, for Field ID 58, I want to reiterate all object ID values ​​and for each one, delete the most recent object-value and transaction.

You can see the schema description here:

and here:

If your structure is not with INSERT ING data UNIX_TIMESTAMP () , then the basis of your entire database structure sequence However, it can be difficult if you add UNIX_TIMESTAMP () then you can use ORDER BY correctly.

No comments:

Post a Comment