Multiple joins rewritten to be correct