Producfy

Latest row per ID SQL builder

Enter your table and columns to get a query that keeps only the newest row for each ID.

Why add a tie-breaker column?

A tie-breaker makes the result repeatable when two rows share the same timestamp. Without one, the database can return either row, and the answer may change between runs. Use a unique, increasing column such as an event ID.

How was this builder checked?

The DuckDB output and the subquery form used for PostgreSQL, MySQL and SQL Server are run against sample data in DuckDB by our test suite. The queries haven't been run on those other databases, so try the result on a small sample first. For a full walkthrough, see Keep the latest status row per task.