QUERY, SET, ROWS 165 4 5 6 Alex Bob Carl With the argument distinct=True, you can specify that you only want to select distinct records. This has the same effect as grouping using all specified fields except that it does not require sorting. When using distinct it is important not to select ALL fields, and in particular not to select the "id" field, else all records will always be distinct. Here is an example: 1 2 3 4 5 for row in db().select(, distinct=True): print Alex Bob Carl With limitby, you can select a subset of the records (in this case, the first two starting. | 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 3 1 2 3 4 QUERY SET ROWS 165 Alex Bob Carl With the argument distinct True you can specify that you only want to select distinct records. This has the same effect as grouping using all specified fields except that it does not require sorting. When using distinct it is important not to select ALL fields and in particular not to select the id field else all records will always be distinct. Here is an example for row in db .select distinct True print Alex Bob Carl With limitby you can select a subset of the records in this case the first two starting at zero for row in db .select limitby 0 2 print Alex Bob Currently limitby is only partially supported on MSSQL since the Microsoft database does not provide a mechanism to fetch a subset of records not starting at 0. Logical Operators Queries can be combined using the binary AND operator rows db Alex 3 .select for row in rows print 4 Alex and the binary OR operator rows db Alex 3 .select for row in rows print 1 Alex You can negate a query or sub-query with the binary operator rows db Alex 3 .select for row in rows print 2 Bob 3 Carl or by explicit negation with the unary operator 166 THE DATABASE ABSTRACTION LAYER 1 2 3 4 1 2 1 1 1 2 3 4 5 1 2 3 4 5 rows db Alex 3 .select for row in rows print 2 Bob 3 Carl Due to Python restrictions in overloading AND and OR operators these cannot be used in forming queries. The binary operators must be used instead. count delete update You can count records in a set print db 0 .count 3 You can delete records in a set db 3 .delete And you can update all records in a set by passing named arguments corresponding to the fields that need to be updated db 3 .update name Ken Expressions The value .