At first I thought this was exactly what I was looking for... but after trying, sorry, but this query doesn't work for me... it returns 0 records, while the previous one is returning the right number. It looks like the GROUP BY selects one of the dates (the first record found) for the grouping, then the HAVING clause filters all grouping records having a selected date <> max(date), leaving 0 records. Trying:
SELECT param, date, max(date) , value FROM param_values GROUP BY param HAVING date=max(date) (that is, add the 'date' column in the select) you can see what date is selected, and why the HAVING clause is filtering everything out. So that's why I need to use the subselect... Right now I got it working perfectly using raw db.executesql(...). In other thread I found a different but similar problem, that needed something not implemented that would be like "Subtables" or similar... Greets. On 18 jul, 00:46, Vasile Ermicioi <[email protected]> wrote: > you can do that with only one query > > SELECT param, max(date) , value > FROM param_values > GROUP BY param > HAVING date=max(date) > > _max_date = db.param_values.date.max() > rows = db(db.param_values).select(db.param_values.param,_max_date, > db.param_values.value, groupby=db.param_values.param, > having=db.param_values.date=_max_date)

