title: Arma 2 DayZ Epoch SQL dead body cleaner
body: <p>I have been trying to figure out a way to do something like what this <a href="https://stackoverflow.com/questions/7238983/delete-all-records-except-the-most-recent-one?newreg=344a5f29c5f64ad494d0fc76bac5b82a">Delete all records except the most recent one?</a>
  But I have been unable to apply it to my circumstance.</p>
  
  <p>My circumstance:
  <a href="https://gyazo.com/178b2493e42aa4ec4e1a9ce0cbdb95d3" rel="nofollow noreferrer">https://gyazo.com/178b2493e42aa4ec4e1a9ce0cbdb95d3</a></p>
  
  <pre><code>SELECT * FROM dayz_epoch.character_data;
  
  CharacterID, PlayerUID, InstanceID, Datestamp, LastLogin, Alive, Generation
  
  5 |76561198068668633|11|2016-05-31 18:21:37|2016-06-01 15:58:03|0|1
  6 |76561198068668633|11|2016-06-01 15:58:20|2016-10-08 21:30:36|0|2
  7 |76561198068668633|11|2016-10-08 21:30:52|2016-10-09 18:59:07|1|3
  9 |76561198010759031|11|2016-10-08 21:48:32|2016-10-08 21:53:31|0|2
  10|76561198010759031|11|2016-10-08 21:53:55|2016-10-09 19:07:28|1|3
  </code></pre>
  
  <p>(Look at image above) So I am currently trying to make a better method for deleting dead bodies from my database for my DayZ Epoch server. I need a code to delete Where ALIVE = 0 if that same PlayerUID has another instance where it is ALIVE = 1.</p>
  
  <p>The other thing the code could do is just delete all players except the most recent one for each PlayerUID. I hope this makes sense. It's hard to explain. The first link explains better for me.</p>
  
  <p>But basically, I want to delete any dead player that now has an alive player with that same PlayerUID. If I were better at coding, I could see many variables I could use like PlayerUID (a must), Datestamp, Alive, and generation. Probably only need 2 of those, one being the PlayerUID.</p>
  
  <p>Thanks a bunch.</p>
  
  <p>The easiest to me seems like it would be something like: SORT by PlayerUID AND FOR EACH PlayerUID DELETE ALL EXCEPT(?) newest Datestamp.
  This would keep the player stats from their dead body in case they do not create a new character before this script is called.</p>