How to add db_select condition by using two concatenated fields? So I have users with a field_first_name and a field_last_name and I need my query condition to be something like:

"field_first_name + ' ' + field_last_name LIKE :q". 


Currently I have:

-&gt;condition(db_or()-&gt;condition('fn.field_first_name_value', $q, 'like')-&gt;condition('ln.field_last_name_value', $q, 'like'))


so if first name is "John" and last name is "Smith" and I search for "John S" I get nothing because it doesnt match the first OR last name, I need to check if it matches the firstname + the last name.

How do I do this in Drupal 7?
You can try something like the following. You build the name with a small sql expression and then can use it within the where clause.

$select = db_select('people_table', 'p');
$select-&gt;addField('id');
$select-&gt;addExpression("CONCAT(p.first_name, ' ', p.last_name)", 'full_name');
$select-&gt;condition('p.full_name', $some_name, 'LIKE');
$results = $select-&gt;execute();