+ Start a Discussion
hideawayguyhideawayguy 

soql query gurus please have a look

hey folks i basically want to do this

 

select Email, FirstName, LastName, Id from Contact where (email address exists more than once in the contact table) order by Email

 

any ideas? 

levaleva

Don't do in SOQL (only SOQL) aggregations in SOQL are hairy. mix in some APEX. Something like this:

Map<Id, Integer> emailCount = new Map<String, Integer>();
Map<Id, Contact> contacts = [select Email, FirstName, LastName, Id from Contact];
Contact result = new Contact[]{};
for (Contact c : contacts.values()){
  Integer idx = emailCount(c.Id);
  if(idx = null)
    idx = 0;
  idx++;
  emailCount.put(c.Id, idx); 
}

for(Id cid : emailCount.keySet()){
  Integer i = emailCount.get(c.Id);
  if(i < 0)
    result = contacts.get(c.Id);
}

 

 

hideawayguyhideawayguy
thanks leva i'll give it a shot!