Inner Join Showing Last Record of Joined Table

Posts   
 
    
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 12-Oct-2010 08:49:52   

Hello

I have numerous tables which I am inner joining together but the one table I need to only pull the last record of that table based on the descending order of a column.

Simplistically there is a table called Calls and a table called CallComments. The Calls table I need to list all the records in this table based on a custom search criteria and the CallComments table I need to just list the last record (Description & EntryDate columns) based on the EntryDate. Is this possible?

Regards, Simon

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 12-Oct-2010 10:47:49   

Use a prefetchPath to the CallComment entity, specify 1 for the maxAmountOfItemsToReturn parameter and pass a sortExpression for the additionalSorter parameter.

smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 12-Oct-2010 12:16:14   

Walaa wrote:

Use a prefetchPath to the CallComment entity, specify 1 for the maxAmountOfItemsToReturn parameter and pass a sortExpression for the additionalSorter parameter.

Do you have sample code which shows this?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 12-Oct-2010 12:29:07   

Just check the manual for Using PrefetchPaths

You will need to use the following overload for the prefetchPath.Add() method:

public virtual IPrefetchPathElement2 Add( 
   IPrefetchPathElement2 elementToAdd,
   int maxAmountOfItemsToReturn,
   IPredicateExpression additionalFilter,
   IRelationCollection additionalFilterRelations,
   ISortExpression additionalSorter,
   IEntityFactory2 entityFactoryToUse,
   ExcludeIncludeFieldsList excludedIncludedFields
)
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 12-Oct-2010 12:31:41   

Walaa wrote:

Just check the manual for Using PrefetchPaths

You will need to use the following overload for the prefetchPath.Add() method:

public virtual IPrefetchPathElement2 Add( 
   IPrefetchPathElement2 elementToAdd,
   int maxAmountOfItemsToReturn,
   IPredicateExpression additionalFilter,
   IRelationCollection additionalFilterRelations,
   ISortExpression additionalSorter,
   IEntityFactory2 entityFactoryToUse,
   ExcludeIncludeFieldsList excludedIncludedFields
)

So if I create a TypedList with the INNER JOINs and the relevant fields will the prefetch path work with with it?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 12-Oct-2010 21:11:59   

No, PreFetch paths are for fetching entities and their related entities (an entity graph). TypedLists are flat lists of entity data (like a DataTable). The prefetch path Walaa demonstrated should do what you need.

Matt