Fix table join (fixes #7068)

and fixes #6840