Relation on subqueries and Joins