What does mean "DOES NOT WORK? Are you getting an OperationalError?

Use the argument *groupby *instead of *distinct*, and you'll get the 
desired results. 


On Sunday, May 8, 2016 at 9:33:44 AM UTC+2, PRACHI VAKHARIA wrote:
>
>
>
> *How To Select Only The Latest Rows from a Table*
>
> For a Table structure as below:
> *Table(*
> *PrimaryKey,*
> *FieldName1,*
> *FieldName2,*
> *Time)*
>
> FieldName1 and FieldName2 are not unique.
>
> *Goal: To select only the latest row for each FieldName2*
>
> *Items = db(db.Table.FieldName1 != Value1).select(orderby=~db.Table.Time, 
> limitby=limitby, distinct=db.Table.FieldName2)*
>
> How to write the above statement so that it selects All the rows from the 
> Table such that:
> – For any given condition which here is: *db.Table.FieldName1 != Value1** 
> (works)*
> – Select All Rows from Table* (works)*
> – Order those rows by Time field* (works)*
> – limit selection by limitby number* (works)*
> *– And Selects only the Latest row for FieldName2 : Latest measured by 
> Time** ( **distinct=db.Table.FieldName2  DOES NOT WORK)*
>
>
> Thank you, very much for reading. Only the part of selecting the distinct 
> last element for FieldName2 does not work and I cannot figure it out. I 
> hope someone can help.
>
>
>
> —
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to