For this kind of thing, you can use 2 approaches. Jens has already shown.
Another is to use the "DISTINCT ON" clause:
CREATE VIEW lastOrders AS SELECT DISTINCT ON (customerID) id, customerID, timestamp FROM orders ORDER BY customerID, timestamp desc;
user80168
source share