I have two tables – Customers, and Orders. Each Customer will have 1..n Orders. They have a relation on a Foreign Key to the Customers table in the Orders table. So far, so DB 101.
I need a query that will return a single row per Customer, together with the date and Order ID of that customer’s latest order. ALL Customers have at least one order. I can easily do this with a function, but I’d prefer to do it in SQL.
In case of auto incremented ID-s, and no variance with dates, the solution is that simple: