On Jan 19, 2008 10:20 PM, Oleg Broytmann <[EMAIL PROTECTED]> wrote:
> On Sat, Jan 19, 2008 at 01:08:38PM +0100, Petr Jake?? wrote:
> > trying to select ALL rows from the table with the "max" value in a specified
> > field
> > I can go:
> >
> > tmax=Prodcats.select().max('tStamp')
> > for row in Prodcats.selectBy('tStamp' == tmax):
> >     print row
> >
> > Just wander if there is some other way how to get rows with max (min....)
> > values in specified field from the table
>
>    This is the best you can do. It possible to use HAVING clause (not in
> .select(), of course, but in sqlbuilder.Select()) or a subquery, but they
> are more complex solutions.

One can also you subselects:

from sqlobject import IN
from sqlobject.sqlbuilder import Select

for row in 
Prodcats.select(IN(Prodcats.q.tStamp,Select(Prodcats.q.tStamp,orderBy=Prodcats.q.tStamp,limit=1))):
  print row

I haven't actually tested this, but I think the theory is sound. There
may be a better way to phrase this subselect (e.g. without using IN or
limit) but I'll leave that as an exercise for the reader. :P

Schiavo
Simon

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to