How do I get all the users in an organic group with specific role programatically?
It's just a simple sql query, no joins needed:

ie. select uid from og_users_roles where rid=3 and gid=835;

  $members = array();
  $current_members = db_select('og_users_roles', 'ogur');
  $current_members-&gt;fields('ogur', array('uid'));
  $current_members-&gt;condition('ogur.rid', $rid);
  $current_members-&gt;condition('ogur.gid', $gid);

  $result = $current_members-&gt;execute();
  while ($res = $result-&gt;fetchAssoc()) { $members[] = $res['uid'];}

  // Remove duplicate items.
  $members = array_keys(array_flip($members));