aggregate function in subquery

Posts   
 
    
mwatts
User
Posts: 1
Joined: 02-May-2012
# Posted on: 02-May-2012 14:43:04   

I can't imagine this isn't possible and it probably isn't even that hard, but I can't get it working.

How do I create a predicate expression to generate the following SQL query:


SELECT * FROM Workflow as W1
WHERE W1.[Version] = (SELECT MAX([Version]) FROM Workflow AS W2 WHERE W2.Code = W1.Code)

The idea is to fetch the Workflow records with the highest version. The Code field is a unique key.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-May-2012 19:51:00   

You can use a ScalarQueryExpression as in the following thread, you'll nneed to use the overload that accepts an Aggregate function. http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=20266