Allow joining on subqueries, fixes #399