title: Retrieving the last record in the repeating sequences with the same values
body: <p>could anyone help me with this:</p>
  
  <p>The records are from attendance tracking software.
  Any employee could accidentally check in or check out more than once, and even worse (first 3 rows) -  on different readers.
  Entrance: 1101, 1102. Exit: 101, 102.</p>
  
  <pre><code>SELECT * FROM `attendance` WHERE ATUserID = 856 AND (ATReaderID = 101 OR ATReaderID = 102 OR ATReaderID = 1101 OR ATReaderID = 1102);
  +--------+------------+----------+----------+------------+
  | ATid   | ATDate     | ATTime   | ATUserID | ATReaderID |
  +--------+------------+----------+----------+------------+
  | 403396 | 2017-05-08 | 07:55:20 |      856 |       1102 |
  | 403399 | 2017-05-08 | 07:55:22 |      856 |       1102 |
  | 403450 | 2017-05-08 | 07:55:40 |      856 |       1101 |
  | 407934 | 2017-05-08 | 16:11:40 |      856 |        102 |
  | 407940 | 2017-05-08 | 16:11:45 |      856 |        102 |
  | 409990 | 2017-05-09 | 07:56:35 |      856 |       1102 |
  | 411490 | 2017-05-09 | 07:56:40 |      856 |       1102 |
  | 413525 | 2017-05-09 | 15:59:40 |      856 |        102 |
  | 413583 | 2017-05-09 | 15:59:52 |      856 |        102 |
  | 413603 | 2017-05-10 | 07:54:50 |      856 |       1101 |
  | 422315 | 2017-05-10 | 16:01:00 |      856 |        101 |
  +--------+------------+----------+----------+------------+
  </code></pre>
  
  <p>I would like to get only the last one event in every sequence (ATReaderID):</p>
  
  <pre><code>+--------+------------+----------+----------+------------+
  | ATid   | ATDate     | ATTime   | ATUserID | ATReaderID |
  +--------+------------+----------+----------+------------+
  | 403450 | 2017-05-08 | 07:55:40 |      856 |       1101 |
  | 407940 | 2017-05-08 | 16:11:45 |      856 |        102 |
  | 411490 | 2017-05-09 | 07:56:40 |      856 |       1102 |
  | 413583 | 2017-05-09 | 15:59:52 |      856 |        102 |
  | 413603 | 2017-05-10 | 07:54:50 |      856 |       1101 |
  | 422315 | 2017-05-10 | 16:01:00 |      856 |        101 |
  +--------+------------+----------+----------+------------+
  </code></pre>
  
  <p>Can't rely on date column (last entrance and exit for each day) because of night shifts (entrance today / exit tomorrow), and allowed multiply entrances/exits per day.</p>
  
  <p>Tried to workout with this solution <a href="https://stackoverflow.com/questions/1313120/retrieving-the-last-record-in-each-group">Retrieving the last record in each group</a>, unsuccessfully.</p>