+ Start a Discussion
Jessie GrenfellJessie Grenfell 

Non-selective query help

I'm afraid I already know the answer to this, but does anyone have any ideas as to how I can refine this query so it doesn't hit the non-selective query issue?  The Contact object contains ~120,000 records.  The goal of the query is to check for potential duplicates when new Contacts are being inserted.  The variables here are various substrings of the first and last names of the new Contacts.  Any recommendations on fixing this or another way of accomplishing it would be very much appreciated.



List<Contact> lstDups = [Select Id, FirstName, LastName, Email, UNI__c from Contact where (FirstName =: c.FirstName and LastName =: c.LastName)
or (LastName =: c.LastName and FirstName like: strFirstL2)
or (LastName like: strLastL5 and FirstName like: strFirstL3)
or (LastName like: strLastR5 and FirstName like: strFirstL3)
or (Email =: c.Email and Email <> 'unknown@email.com')];