I am working on a join query in which I have to get the data from a column which contain the comma separated values.like allowed_activity contain 1,2,3,4,5,6
this the activity_id which is allowed.
So In the query, I am checking that current activity is allowed or not and for that, I have used where_in and also tried find_in_set in where condition.
Here is that part of the query:
$this->db->where_in('a.allowed_activity',$activity_id);
//And With FIND_IN_SET
$this->db->where("FIND_IN_SET($activity_id, a.allowed_activity) !=",0);
Problem or Confusion
When I use where_in it doesn't give me the result. But if I use FIND_IN_SET then it will return the desired result. I thought that where_in can do the task but it didn't.
Just Want to know why
find_in_setworking differently thanwhere_inBecause of both the function work same as finding the data is in comma separated list.
Here is the complete query:
SELECT mycolumns
FROM `table1` as `ea`
LEFT OUTER JOIN `table2` as `a` ON `ea`.`package_id` = `a`.`id`
LEFT OUTER JOIN `table3` as `e` ON `ea`.`employer_id` = `e`.`id`
WHERE `ea`.`card_id` > 0
AND FIND_IN_SET(6, a.allowed_activity) !=0
AND `ea`.`id` = '6'
ORDER BY `ea`.`creation_date` DESC
I am using Codeigniter Active record.