[SalesForce] Get Contact info and CampaignMember status in one query

Is there a way to retrieve contact information (first name, last name) and campaign member status for all members of a campaign in one SOQL query? I know you can get just the contact information with:

select id, lastname, firstname, hci_id__c 
from Contact 
where id in (
  select contactid from campaignmember where contactid='833i0000000q023')

How would I pull the status out of the campaignmember to display it with the name? I know how to do this in SQL with a join. Would this be done with a relationship query?

Best Answer

Campaign Member has a lookup relationship to Contact, so you can read fields from the Contact.

list<CampaignMember> cms = [SELECT Status,  Contact.FirstName, 
                            Contact.LastName, Contact.hci_id__c 
                            FROM CampaignMember 
                            WHERE CampaignId = :campId];

The SOQL and SOSL reference is very good: http://www.salesforce.com/us/developer/docs/soql_sosl/