Fix a tricky case when JOIN clause is used.