MAX in expression

Posts   
 
    
wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 25-Jan-2007 14:02:06   

Hi,

Im trying to turn this SQL into an LLBLGen Expression / SkillEntity:

SELECT S.* FROM [dbo].[Skill] S INNER JOIN [dbo].[Queue] Q ON S.ID=Q.SkillID WHERE Q.[TimeStamp] = ( SELECT MAX(Q2.[TimeStamp]) FROM [dbo].[Skill] S2 INNER JOIN [dbo].[Queue] Q2 ON S2.ID=Q2.SkillID )

I don't know how to perform the subquery, is it possible at all?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jan-2007 15:02:50   

Yeah I think it's possible if turned into the following:

SELECT S.* 
FROM [dbo].[Skill] S
INNER JOIN [dbo].[Queue] Q ON S.ID=Q.SkillID
WHERE 
    Q.[TimeStamp] IN (
     SELECT MAX(Q2.[TimeStamp]) 
     FROM [dbo].[Skill] S2
     INNER JOIN [dbo].[Queue] Q2 ON S2.ID=Q2.SkillID
    )

Note the IN keyord rather than the '='.

Then you can construct the IN predicate using FieldCompareSetPredicate, and set the AggregateFunctionToApply property of the passed EntityField parameter to AggregateFunction.Max

wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 25-Jan-2007 15:30:15   

Walaa wrote:

Then you can construct the IN predicate using FieldCompareSetPredicate, and set the AggregateFunctionToApply property of the passed EntityField parameter to AggregateFunction.Max

Cool, I didn't know you could do that with an EntityField... Thanks! (for the fast reply as well)