Codeigniter – Delete Query

Delete function is used to delete the one or more row data from database table. If you want to delete all data from a table, you can use the truncate() function, or empty_table().


$this->db->delete('tbl_user', array('id' => $id)); 
//DELETE FROM tbl_user WHERE id = $id
$this->db->where('id', $id);
//DELETE FROM tbl_user WHERE id = $id

An array of table names can be passed into delete() if you would like to delete data from more than 1 table.

$tables = array('table1', 'table2', 'table3');
$this->db->where('id', $id);


// DELETE FROM tbl_user


// TRUNCATE table tbl_user;

Delete With Join

$this->db->join("table2", "table1.t1_id = table2.t2_id");
$this->db->where("table2.t2_id", $id);