Allow inner query values to be used in outer query joins. Fixes #340