This is a good candidate for a self-join.
SELECT o.* FROM mytable t -- FromFor every row from This table, CROSS JOIN mytable o -- selectand for every row in the Other (see note #2) table WHERE t.id <> o.id -- such that it is a different row AND o.date > t.date -- with a date later AND t.id = {id} -- than a specific row. Notes:
- Because
>is used in the value comparison, thet.id <> o.idclause can be omitted. In any case, the query planner should figure this stuff out just fine. - The CROSS JOIN starts off a Cartesian product but the WHERE filters bring it back down quickly. In particular the
t.id = {id}clause (assuming thatidhas a unique constraint) brings down the multiplicity to at most one output row for each input row ino.