I’ve implemented an autosuggest search using jQuery, php and SQL server 2008. I’m looking for people by their name. The name of the person is divided in three fields ‘nombres, ‘apellido_paterno’ and ‘apellido_materno’. My autosuggest matches results where one of the three fields looks like the pattern in the input text.
$values = array(':x'=>$data['term'].'%',':y'=>$data['term'].'%',':z'=>$data['term'].'%');
$sql = "SELECT TOP 10 id_persona, nombres +' '+ apellido_paterno +' '+ apellido_materno AS value
FROM personas WHERE nombres LIKE :x OR apellido_paterno LIKE :y OR apellido_materno LIKE :z";
So my query is working fine if you search by name or lastname, however if you search by full name there are no matches. So, how do I add criteria to my query in order to bring full name matches?
Assuming all three are varchar fields, and you are querying a somewhat limited number of records, I would just do: