Use a subquery or CTE for broad compatibility.
Section: Dialect notes
Portable alternative to QUALIFY
sql
sql
WITH ranked AS (
SELECT o.*,
ROW_NUMBER() OVER (
PARTITION BY customer_id
ORDER BY created_at DESC
) AS rn
FROM orders o
)
SELECT *
FROM ranked
WHERE rn = 1;Explanation
This pattern works across most SQL databases that support window functions.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Dialect notes
QUALIFY shortcut in some warehouses
Filter window results without wrapping a subquery.
Remember LAST_VALUE frame semantics
Default frames can make LAST_VALUE look broken.
Be explicit about NULL ordering when needed
Different engines may sort NULLs differently.
Create a supporting index for partition/order keys
Help the database read rows in the right order.