+1  A: 

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
No... but I can see why the question was confusing...Edited to add "For the period of time prior to "f"s arrival, the correct return is c,d and e."
I updated the query
sfossen
note that, prior to f's arrival, that will only return "d", because only d's timestamp will match. (the packets do not arrive either in order, or all at once)
ok.. so I'm thinking if they arrive in order, grab the highest index 1 for you're lowerbound on time and the total for the packet sequence.
sfossen
A: 

If they arrive in order without other packets being written in between, following should also work.

SELECT *
FROM Total t
     INNER JOIN (
       SELECT Total, Timestamp
       FROM Total t
            INNER JOIN (
              SELECT Timestamp = MAX(Timestamp) 
              FROM Total
              WHERE ID = 1
            ) ts ON ts.Timestamp = t.Timestamp.
     ) tit ON tit.Total = t.Total AND tit.Timestamp <= t.Timestamp
Lieven
I may end up going with an approach like this. Unhappily enough, occasionally these timestamps can be off each other by several hours.For the curious, this is remote sensing science data using a very intermittent pipe.
@kiruwa, if that is the case, you can't reliably construct a query to get all the data from the last transmission. If two transmissions with identical totals arrive with several hours interval between it's packets, <irony on>you're doomed... doomed I say <irony off>
Lieven
Yeah, the attempt was just to get something close. The equivalent of the two-stage query:foo = SELECT total FROM table WHERE timestamp = (SELECT MAX(timestamp)...)SELECT * FROM table WHERE total=$foo ORDER BY DESC timestamp LIMIT foo
A: 

This is how I'd do it in sql server, you can convert to mysql syntax.

SELECT *
FROM table
     INNER JOIN (SELECT TOP 1 * FROM table ORDER BY key DESC) AS t ON (table.timestamp = t.timestamp AND table.total = t.total)
Will Rickards
A: 

I ended up going with a slightly different query form:

CREATE VIEW NewestTimestamps AS
  SELECT index, MAX(timestamp) AS maxTS FROM table GROUP BY index;

CREATE VIEW NewestList AS
  SELECT * FROM table AS t
    JOIN NewestTimestamps sub ON t.timestamp = sub.maxTS AND sub.index = t.index
  WHERE t.total = (SELECT t2.total FROM table AS t2 
    WHERE timestamp = (SELECT MAX(timestamp) FROM table)
  ); 

This list is not precisely what I asked for, but it seems actually impossible to distinguish newer and older data reliably. Instead, this will give me the newest element at index 1, then index 2, etc... Additionally, the WHERE clause will limit the size of the view to the size of the most recently arrived queue.

Note that the first view is required since mysql does not allow subqueries in the FROM clause in a view.