complex query using TableGateway