[eluser]mddd[/eluser]
You are not comparing the string table2_id.
Your WHERE statement takes effect BEFORE the GROUP_CONCAT is done. That means that WHERE table2_id = {x} refers to the field table2_id in your table. NOT to the pseudo-column table2_id that contains the GROUP_CONCAT result.
Write it like this and it will be clearer:
Code:
$this->db->select('table1.*, GROUP_CONCAT(DISTINCT table2_id) AS found_table_ids');
$this->db->join('table2', 'table2_id = table1_table2_id', 'left');
if($table2 != '')
{
$this->db->where('table2_id', $table2);
}
If you wanted to match the GROUP_CONCAT you would have to write
Code:
HAVING found_table_ids = '28,239,20'