One easy option is to use Views to generate the SQL (appears below the view its self when you press the preview button) for you and then use the [Drupal SQL abstraction layer][1] to get the results you need if you need to get access to the raw data rather than display a View.
It'd look a bit like this:
$result = db_query('SELECT users.uid AS uid,
users.mail AS users_mail,
users.name AS users_name
FROM users users');
while ($existing_user = db_fetch_object($result)) {
print_r($existing_user); // or do whatever
}
Just add more fields to the view to get the complete query.
[1]:
[To see links please register here]