Replacing a PHP loop with a MySQL Query
Sure, just use a subquery

select distinct u.*
from 
  user_hashes uh
  inner join users u on uh.user_id = u.id
WHERE 
  uh.hash IN
  (
    select hash
    from user_hashes buh
    where user_id = ?
  )