query I'm suggesting:
SELECT *
FROM packets
WHERE total = ( SELECT total
FROM packets
WHERE timestamp = ( SELECT MAX(timestamp) FROM packets ))
AND timestamp >= ( SELECT MAX(timestamp) FROM packets WHERE idx = 1 )
ORDER BY timestamp DESC;
Inaction:
mysql> create table packets( id bigint(20) AUTO_INCREMENT primary key, data char(1), idx int(10), total int(10), timestamp datetime );
Query OK, 0 rows affected (0.00 sec)
mysql> insert into packets( data, idx, total, timestamp ) values( 'a', 1 ,2,'2009-01-02 01:01:32'),
-> ('b' ,2 ,2,'2009-01-02 01:03:32'),
-> ('c' ,1 ,3,'2009-01-03 01:01:32'),
-> ('d' ,2 ,3,'2009-01-03 01:04:32'),
-> ('e' ,3 ,3,'2009-01-03 01:02:32'),
-> ('f' ,1 ,2,'2009-01-05 01:01:32');
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql> SELECT *
-> FROM packets
-> WHERE total = ( SELECT total
-> FROM packets
-> WHERE timestamp = ( SELECT MAX(timestamp) FROM packets ))
-> AND timestamp >= ( SELECT MAX(timestamp) FROM packets WHERE idx = 1 )
-> ORDER BY timestamp DESC;
+----+------+------+-------+---------------------+
| id | data | idx | total | timestamp |
+----+------+------+-------+---------------------+
| 6 | f | 1 | 2 | 2009-01-05 01:01:32 |
+----+------+------+-------+---------------------+
1 row in set (0.00 sec)
mysql> delete from packets where id = 6;
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM packets WHERE total = ( SELECT total FROM packets WHERE timestamp = ( SELECT MAX(timestamp) FROM packets )) AND timestamp >= ( SELECT MAX(timestamp) FROM packets WHERE idx = 1 ) ORDER BY timestamp DESC;
+----+------+------+-------+---------------------+
| id | data | idx | total | timestamp |
+----+------+------+-------+---------------------+
| 4 | d | 2 | 3 | 2009-01-03 01:04:32 |
| 5 | e | 3 | 3 | 2009-01-03 01:02:32 |
| 3 | c | 1 | 3 | 2009-01-03 01:01:32 |
+----+------+------+-------+---------------------+
3 rows in set (0.00 sec)
mysql>
sfossen
2009-03-04 21:13:44