'How to search string in concat string in codeigniter [duplicate]

Here is my query

$this->db->select('
CONCAT(customers.first_name, " ", customers.last_name) AS full_name
');
$this->db->where('full_name', $customerSearch);
$run_q = $this->db->get('customers');

But I receive errors.

Unknown column 'full_name' in 'where clause'

What's wrong with me?



Solution 1:[1]

Please try this:

$this->db->select('
CONCAT(customers.first_name, " ", customers.last_name) AS full_name
');
$this->db->where(CONCAT(customers.first_name, " ", customers.last_name), $customerSearch);
$run_q = $this->db->get('customers');

You are getting error because you can't use alias of 'derived column'(i.e. full_name) in 'where' clause.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nishant Gupta