As dangermouse said it simply deletes the first row MySQL finds; this will tend to be the oldest unit, but not necessarily (it'll be whatever is faster for MySQL)
Katsarephat; actually I already did that part just like you said, a few months back ;-)
I used a recursive graph spanning algorithm to populate the table, but the table is currently unused.
It's called pD_UnitDestroyIndex, and it has 3 columns; country, territory, unit type and index.
So England goes from (England, Armenia, Fleet, 1) to (England, London, Army, 120), and it goes by the preferred rules in the DATC :-)
But I didn't get around to hooking it up to the unit creation adjudicator and testing it (not as fun as the graph traversal algorithm itself) :-(
If anyone knows some SQL and wants to take a crack at it, it'd just be an altered DELETE query (plus some testing):
http://phpdiplomacy.net/doc/phpDoc/__filesource/fsource_GameMaster_Orders_gamemasterordersunitplacing.php.html#a113