Obavam sa ze jednym dotaozm to nepojde (aspon mne nenapada ziaden sposob).
Predpokladam ze uzivatelov nebudu tisice, takze ja by som si
1. vybral uzivatelov distinctom a v cykle pre kazdeho
2. zistil id 20-teho zaznamu a
3. vymazal vsetky ktore su pred tym id (co by nemal byt problem pri predpoklade rastuceho id)
Kód:
1. SELECT DISTINCT id_user AS nas_user FROM table
2. SELECT MIN(id_zaznam) AS nas_zaznam FROM (SELECT id_zaznam FROM table WHERE id_user = $nas_user ORDER BY id_zaznam DESC LIMIT 20) AS t
3. DELETE FROM table WHERE id_user = $nas_user AND id_zaznam < $nas_zaznam