0

i m applying union on single table and i want apply inner join with union in codeigniter on it. how can i do that i have tryed many ways but everytime i got syntax error

this is my code:-

$this->db->select(' COUNT(marks.old_id) AS count, MIN(marks.mark) AS min , MAX(marks.mark) AS max ')
        ->from('marks')
->where('type', 'hard')
->group_by('marks.id');
$this->db->get(); 
    $query1 =  $this->db->last_query();

$this->db->select(' COUNT(marks.old_id) AS count, MIN(marks.mark) AS min , MAX(marks.mark) AS max ')
        ->from('marks')
->where('type', 'easy')
->group_by('marks.id');
$this->db->get(); 
    $query2 =  $this->db->last_query();

$query = $this->db->query($query1 . ' UNION ' . $query2);

// $this->db->select('newuser.*')
// ->from('newuser')
// ->join('marks', 'newuser.id = marks.old_id', 'left')
// ->group_by('newuser.id')
// ->order_by('newuser.id', 'ace');



return $query->result();

please help me...

2 Answers2

1

CodeIgniter's active records don't support UNION, so you would just write your query and use the active records query method. , Please check this post Union query with codeigniter

  • my union is working fine. i just need to apply inner join on it, i want to know how can i apply inner join on it.. because every time i apply inner join got syntax error – shikha singh Aug 11 '21 at 10:34
-1

Codeigniter active record not supporting a union Write a raw query for union...