issue-95: make SQL all be in one query, props to Frankie