You didn't specify how the names are organized into their columns. If 'Ray' could be in either firstname or lastname and the same with 'Hunter' then use UNION instead of OR
firstname = 'Ray' AND lastname = 'Hunter' UNION lastname = 'Ray' AND firstname = 'Hunter' will be faster than using an OR If you know which columns they are in just select on that. -- Walt On 07/18/2013 07:03 PM, Wade Shearer wrote: > Imagine a database with first and last names in separate columns. I need to > be able to search by "<first name> <last name>" or "<last name> <first > name>". Is there a better way than this? > > SELECT lastname, firstname > FROM wherever > WHERE (CONCAT(lastname, ', ', firstname) LIKE "%Ray Hunter%" OR > CONCAT(firstname, ' ', lastname) LIKE "%Ray Hunter%" ) > > _______________________________________________ > > UPHPU mailing list > [email protected] > http://uphpu.org/mailman/listinfo/uphpu > IRC: #uphpu on irc.freenode.net > _______________________________________________ UPHPU mailing list [email protected] http://uphpu.org/mailman/listinfo/uphpu IRC: #uphpu on irc.freenode.net
