by Randy Thornton.
Ned,
Check here for a solution: https://moodle.org/mod/forum/discuss.php?d=331396.
Your solution with the IN statement doesn't work completely because when you have more than one custom profile field, while your query joins those to the user id properly, it does not distinctly join the profile field and its data.
The solution is in the link above where you will see there's a separate JOIN and table alias for each field you want with an AND restriction by the profile field shortname.
Randy