Search code examples
phpcodeignitergroup-byfind-in-set

Usage of FIND_IN_SET in query


  $query=$this->db
->select(a.date,group_concat(s.name)
->from("tbl_attendance a,tbl_students s") 
->WHERE ("FIND_IN_SET(s.student_id, a.attendance)")->group_by("a.date")
->get();

I wanted to know whether I have used the FIND_IN_SET and group_by functions correctly. Thanks in advance


Solution

  • FIND_IN_SET() returns the position of a string if it is present (as a substring) within a list of strings

    so you should search if a value is != 0

    eg:

    ->where("FIND_IN_SET(s.student_id, a.attendance) !=", 0)
    ->group_by("a.date")