wrote first iteration of SQL subquery builder