Getting x orders, each placed by another customer

Posts   
 
    
Pablo
User
Posts: 81
Joined: 21-Mar-2005
# Posted on: 25-Nov-2009 14:54:31   

Hello, Could anyone be so kind to have a look at the following ...?

I have an Order and Customer table. Each Order is placed by a Customer. Customer can place more than 0 Orders. Order has CreateDateTime.

I want to get a set of 'most recent created' orders, but each order should have a unique customer.

So say ... order 8, 16h00, customer 1 order 7, 15h00, customer 2 order 6, 14h00, customer 2 order 5, 15h45, customer 3 order 4, 15h40, customer 3 order 3, 15h35, customer 3 order 2, 15h30, customer 4 order 1, 15h25, customer 4

I would like to get an ordercollection with the orders no: 8, 7, 5 and 2

Thanx for any suggestion, Paul

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 25-Nov-2009 16:48:59   

So you want to get the latest order for each customer.

This can be done by Fetching the Customers, and supply a prefetchPath to orders. You should pass a sortExpression the prefecthPath to sort on the CreateDateTime Descendingly, and specify 1 as the maximumNumberOfItems for the prefetchPath (Top 1).

This will fetch all Customers, and the latest Order for each Customer.

Pablo
User
Posts: 81
Joined: 21-Mar-2005
# Posted on: 25-Nov-2009 16:58:54   

Hi Walaa, Your first line is correct! Your suggestion ... perfect! Many thanx!!! Paul