Ascendion's delivery analytics team needs a report showing the most recent activity records across its project portfolio. Write a PostgreSQL query that returns the latest 20 activity rows, preserving activities even when employee or project details are unavailable.
Requirements
- Use a CTE to identify the latest 20 rows from
activity_events.
- Sort by
occurred_at descending, using event_id descending as a deterministic tie-breaker.
- Use
LEFT JOIN to include activity rows with missing employee or project references.
- Return the event ID, timestamp, event type, employee name, and project name in newest-first order.
The sample contains fewer than 20 activity rows, so the query should return every available row while still using LIMIT 20.