Gør brug af underforespørgsler.
eksempel
#Create where clause
$this->db->select('id');
$this->db->from('table2');
$this->db->where('table2.title', $title);
$where_clause = $this->db->get_compiled_select();
#Create main query
$this->db->where('table1.user_id', $user_id);
$this->db->where("`id` NOT IN ($where_clause)", NULL, FALSE);
$this->db->delete('table1');
Referencer
- stjålet herfra:https://stackoverflow.com/a/16303021/1275832
- om underforespørgsler:http://www.mysqltutorial.org/mysql-subquery/
- kompileret vælg:https://github.com/NTICompass/CodeIgniter-Subqueries