Q:

SOQL Join Contact and User?

In my org, the User object has a lookup field to a Contact.  In my Apex class, I need to return a data set that includes Contacts and the User Id associated with each Contact.  The query below returns the Contacts I need:
Select Id, Name, LastName, FirstName, Account.Name, Account.ccrz__E_AccountGroup__r.Name from Contact where Account.ccrz__E_AccountGroup__c != null 
order by FirstName

All I need now is to return the User Object SFID for each Contact.  Is there a way I can include the associated User object Id in the above query?

A:

It would be easier to have your base query be the User instead of contact.
Select Id, Contact.Id, Contact.Name, Contact.LastName, Contact.FirstName, Contact.Account.Name, Contact.Account.ccrz__E_AccountGroup__r.Name 
from User 
where Contact.Account.ccrz__E_AccountGroup__c != null 
order by Contact.FirstName

