#61

Select Last N Records

EASYSortingPOSTGRESQL

Problem Description

In a data pipeline, each record processed by an ingestion job is logged to a table with a monotonically increasing `id`. When debugging a pipeline run or auditing what arrived most recently, you need to inspect the last `N` entries — the records with the highest IDs — returned in ascending order so they read chronologically. Write a query to retrieve the last 5 records from the `employees` table, ordered by `id` ascending in the final output.

Topics

subquery

Asked at Companies

bytedance

Solve This Problem

Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.

Start Solving →