Found that the problem ocurred when attempt.id != attempt.uniqueid as the sql was using the wrong field to join the question records.