Could it be that the user was at some point enrolled and no longer is enrolled on the course and had completed it previously? I don't think the completion record is deleted when the user is unenrolled which means you would have to determine the enrolled status of the user.
General developer forum
Course Completion Query - Moodle 3.5
This discussion has been locked so you can no longer reply to it.