0
 public function delete($group_id)
 {
      $this->db->where('t1.*, t2.*, t3.*, t4.*, t6.*, COUNT(t5.id) AS total_students')
               ->join('groups_days AS t6', 't1.group_id = t6.group_id') 
               ->join('groups_members AS t5', 't1.group_id = t5.group_id')
               ->group_by('t1.group_id')
               ->delete("groups AS t1")
               ->result();
 }

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `t1` WHERE t1., t2., t3., t4., t6.*, COUNT(t5.id) AS total_students' at line 1

DELETE FROM `groups` AS `t1` WHERE t1., t2., t3., t4., t6.*, COUNT(t5.id) AS total_students

Filename: D:/www/domains/uzdev/taraqqiyot/application/models/Group_model.php

My delete not working and showing above error. What is wrong here

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
Ravshan Abdurasulov
  • 527
  • 1
  • 6
  • 17

1 Answers1

1

According to this link you can't do delete with join with CodeIgniter Active Records: link

Another option is using several queries as many as number of tables:

$this->db->delete('groups', array('group_id'=>$group_id));
$this->db->delete('groups_days', array('group_id'=>$group_id));
$this->db->delete('groups_members', array('group_id'=>$group_id));
Community
  • 1
  • 1
Furkat U.
  • 431
  • 5
  • 20