2015-09-21T06:47:28 *** ecthiender has joined #amclug 2015-09-21T06:47:28 *** ecthiender has quit IRC (Changing host) 2015-09-21T06:47:28 *** ecthiender has joined #amclug 2015-09-21T07:07:29 *** zoso has joined #amclug 2015-09-21T11:17:21 ecthiender, ping 2015-09-21T11:58:35 *** zoso has quit IRC (Ping timeout: 252 seconds) 2015-09-21T11:59:00 *** zoso has joined #amclug 2015-09-21T13:29:55 ecthiender, this is the query I am running select count(sweets.id), users.username from sweets, users where sweets.user_id=users.id group by users.username; 2015-09-21T13:47:32 ecthiender, found the way to do it, here is the query in sqlalchemy, db.session.query(User.username, func.count(Sweet.id)).filter(Sweet.user_id == User.id).group_by(User.username).all() 2015-09-21T14:01:38 the difference between a query method on table object and query method on session object is that, table object's query has predefined select expression and queries are meant to run on the table itself. 2015-09-21T14:06:12 the queries become a subquery on the table.. 2015-09-21T14:37:19 *** ecthiender has quit IRC (Quit: Leaving) 2015-09-21T17:27:14 *** zoso has quit IRC (Ping timeout: 260 seconds)