I would think a join could get you there in one query. Something like: users = db((db.auth_user.id==db.auth_membership.user_id) & (db.auth_membership.group_id==db.auth_group.id) & (db.auth_group.role=='Super admin')).select() for user in user: #do something
The query is messier but I worry that your query is hitting the DB on each iteration through the loop (anyone know?). Also note that you have to reference the result set differently because of the joins. It would help to take a look at "users" in the raw (ie, return dict(users=users) and just take a look at the data). It's going to be something like: user.auth_user.first_name, etc. I realize that joins force the more complicated representation but am wondering if there are any solutions? For example, could it be made so that if we code "select(db.auth_user)" that it only return the auth_user table elements?