我有以下三个表
+----------+ +--------+ +-------------+
| adv | | member | | removed_adv |
+==========+ +========+ +=============+
| id | | id | | id |
| group | | group | | adv_id |
| category | | email | | member_id |
| title | | pw | +-------------+
| path | +--------+
| duration |
+----------+
我要做的是从表 adv 获取所有数据,其中成员表的组等于< em> adv 表的组。如果成员表的 id 等于_removed_adv_表的_member_id_,则应从结果集中删除该数据。
我正在使用CodeIgniter的Active Record。
有人可以帮帮我吗?我真的不知道该怎么做。答案 0 :(得分:1)
你可以试试这个:
select * from adv join member
on adv.group=member.group
where member.id not in (select member_id from removed_adv)
对于CodeIgniter:
$removed = // get removed records member_id to here;
$CI->db->select('ad');
$CI->db->from('adv ad');
$CI->db->join('mem m', 'ad.group=mem.group', 'left');
$CI->db->where_not_in('mem.id', $removed);
$query = $CI->db->get();