如何在codeigniter中为3 where_in()编写查询

时间:2014-11-12 09:01:30

标签: mysql codeigniter

我有一个运行正常的查询,但我不知道怎么写codeigniter

这是我的查询

SELECT id,contact,firstname,email 
FROM `user` 
WHERE `id` IN(SELECT id 
              FROM `hr` 
              WHERE `hr_id` IN(SELECT hr_id 
                               FROM `admin_hr` 
                               where id_admin_hr = 8)
              ) AND `id_category` =1

1 个答案:

答案 0 :(得分:0)

您可以在where()方法中添加子查询部分,试试这个

$this->db->select("id,contact,firstname,email")
        ->where("id IN(SELECT id FROM `hr` WHERE `hr_id` IN(SELECT hr_id FROM `admin_hr` where id_admin_hr = 8))")
        ->where("id_category", 1)
        ->get("user")