Not sure I understand this syntax: (select count(*) cnt from T2) t2_cnt, (select maxrows from T1) max_t1 which seems to be defining new tables, as far as I can see from the later usage such as: ... when t2_cnt.cnt > max_t1.maxrows ... but I can't get that from the SQLite syntax diagrams. In any case, I get this error in the sqlite CLI: Error: no such column: t2_cnt.cnt so I'll have a look at max().