Code:
SELECT Last(Contact.ID) AS LastOfID, Contact.ClientCode, Last(Contact.ContactName) AS LastOfContactName, Last(Contact.ContactAddress) AS LastOfContactAddress, Last(Contact.ContactCity) AS LastOfContactCity, Last(Contact.ContactPostal) AS LastOfContactPostal, Last(Contact.ContactPhoneH) AS LastOfContactPhoneH, Last(Contact.ContactPhoneHLM) AS LastOfContactPhoneHLM, Last(Contact.ContactPhoneHAN) AS LastOfContactPhoneHAN, Last(Contact.ContactPhoneW) AS LastOfContactPhoneW, Last(Contact.ContactPhoneWLM) AS LastOfContactPhoneWLM, Last(Contact.ContactPhoneWAN) AS LastOfContactPhoneWAN, Last(Contact.ContactPhoneC) AS LastOfContactPhoneC, Last(Contact.ContactPhoneCLM) AS LastOfContactPhoneCLM, Last(Contact.ContactPhoneCAN) AS LastOfContactPhoneCAN, Last(Contact.ContactEmail) AS LastOfContactEmail, Last(Contact.ContactEmailCC) AS LastOfContactEmailCC, Last(Contact.ResidencePerm) AS LastOfResidencePerm, Last(Contact.ResidencePermNo) AS LastOfResidencePermNo, Last(Contact.Homeless) AS LastOfHomeless, Last(Contact.Pregnant) AS LastOfPregnant, Last(Contact.PregnantMonths) AS LastOfPregnantMonths, Last(Contact.EmplStatus) AS LastOfEmplStatus, Last(Contact.EmplFulltime) AS LastOfEmplFulltime, Last(Contact.EmplParttime) AS LastOfEmplParttime, Last(Contact.EmplUnemployed) AS LastOfEmplUnemployed, Last(Contact.EmplRetired) AS LastOfEmplRetired, Last(Contact.EmplStudent) AS LastOfEmplStudent, Last(Contact.EmplVolunteer) AS LastOfEmplVolunteer, Last(Contact.EmplHome) AS LastOfEmplHome, Last(Contact.EmplEIA) AS LastOfEmplEIA, Last(Contact.EmplEIARec) AS LastOfEmplEIARec, Last(Contact.EmplEIAApp) AS LastOfEmplEIAApp, Last(Contact.EmplEI) AS LastOfEmplEI, Last(Contact.EmplEIRec) AS LastOfEmplEIRec, Last(Contact.EmplEIApp) AS LastOfEmplEIApp, Last(Contact.EmplIncSrc) AS LastOfEmplIncSrc, Last(Contact.EmplIncSrcOthDesc) AS LastOfEmplIncSrcOthDesc, Last(Contact.OthSysInvCFS) AS LastOfOthSysInvCFS, Last(Contact.OthSysInvCLS) AS LastOfOthSysInvCLS, Last(Contact.Income) AS LastOfIncome, Last(Contact.EduHighest) AS LastOfEduHighest, Last(Contact.EduFormal) AS LastOfEduFormal, Last(Contact.EduHighestPost) AS LastOfEduHighestPost, Last(Contact.EduHighestPostOther) AS LastOfEduHighestPostOther, Last(Contact.FamilyRlshp) AS LastOfFamilyRlshp, Last(Contact.FamilyRlshpOther) AS LastOfFamilyRlshpOther, Last(Contact.FamilyChildren) AS LastOfFamilyChildren, Last(Contact.FamilyChildResp) AS LastOfFamilyChildResp, Last(Contact.FamilyChildResp06) AS LastOfFamilyChildResp06, Last(Contact.FamilyChildResp712) AS LastOfFamilyChildResp712, Last(Contact.FamilyChildResp1317) AS LastOfFamilyChildResp1317, Last(Contact.FamilySituation) AS LastOfFamilySituation, Last(Contact.FamilySituationOther) AS LastOfFamilySituationOther, Last(Contact.FamilyNumInd) AS LastOfFamilyNumInd, Last(Contact.FamilyNumIndChgKid) AS LastOfFamilyNumIndChgKid, Last(Contact.FamilyNumKids) AS LastOfFamilyNumKids, Last(Contact.FamilyNumChgKidWhy) AS LastOfFamilyNumChgKidWhy, Last(Contact.Suicidal) AS LastOfSuicidal, Last(Contact.SuicidalWhy) AS LastOfSuicidalWhy, Last(Contact.RiskFactorsSubstance) AS LastOfRiskFactorsSubstance, Last(Contact.RiskFactorsGambling) AS LastOfRiskFactorsGambling, Last(Contact.RiskFactorsEating) AS LastOfRiskFactorsEating, Last(Contact.RiskFactorsSpending) AS LastOfRiskFactorsSpending, Last(Contact.RiskFactorsHarming) AS LastOfRiskFactorsHarming, Last(Contact.RiskFactorsMental) AS LastOfRiskFactorsMental, Last(Contact.SupportsEducational) AS LastOfSupportsEducational, Last(Contact.SupportsEmplFT) AS LastOfSupportsEmplFT, Last(Contact.SupportsEmplPT) AS LastOfSupportsEmplPT, Last(Contact.SupportsVolunteering) AS LastOfSupportsVolunteering, Last(Contact.SupportsHousingSecure) AS LastOfSupportsHousingSecure, Last(Contact.SupportsHousingTrans) AS LastOfSupportsHousingTrans, Last(Contact.SupportsAfterCare) AS LastOfSupportsAfterCare, Last(Contact.SupportsReferHouseTrans) AS LastOfSupportsReferHouseTrans, Last(Contact.SupportsReferOthProg) AS LastOfSupportsReferOthProg, Last(Contact.SupportsRefusePlan) AS LastOfSupportsRefusePlan
FROM Contact
GROUP BY Contact.ClientCode
ORDER BY Last(Contact.ID) DESC;
And if I join the query it changes the sql to this: