Filter collection with max(column)

Posts   
 
    
Posts: 14
Joined: 13-Apr-2009
# Posted on: 27-May-2010 21:19:57   

Hi

I have a table with a column Version (int), that table also have a column Key, when the other columns change the value in column Key remains unchanged and the column Version is incremented by one.

Something like this: Key Other Version XX XA 1 XX XC 2 YY ZZ 1 YY ZY 2 YY ZW 3

and i want to filter the collection of these entities to only get that (max(version) group by Key): XX XC 2 YY ZW 3

It is possible? How?

Regards

Desbaratizador

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 27-May-2010 22:28:52   

As ever with queries like this, think about the SQL first, and work back from there. Can you create a SQL query that returns the results that you need ?

I'm guessing it will be something like

SELECT Key,Max(Version) FROM table GROUP By Key

If this is the case have a look at the documentation about using GROUP BY to generate DynamicLists

http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/Adapter/Using%20TypedViews,%20TypedLists%20and%20Dynamic%20Lists/gencode_usinggroupbyhaving_adapter.htm

Matt

Posts: 14
Joined: 13-Apr-2009
# Posted on: 07-Jun-2010 16:48:35   

OK.

I'am using the SelfServicing pattern and with this pattern i could use the getMultiAsDataTable method with something like to a GROUP BY filter to obtain the result as a DataTable, but if i want to get the result as a collection of entities?

Desbaratizador

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Jun-2010 04:16:05   

So, you want something like:

SELECT * FROM myTable
WHERE key IN
(SELECT key, MAX(version)
GROUP BY key)

You can achieve that and retrieve entities, using FieldCompareSetPredicate. Give it a try and let us know whether you need further help.

David Elizondo | LLBLGen Support Team