fixed bug when joining subqueries