codeigniter活动记录中的子查询 [英] subquery in codeigniter active record
本文介绍了codeigniter活动记录中的子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT * FROM certs WHERE id NOT IN (SELECT id_cer FROM revokace);
如何在CodeIgniter活动记录中写上述select语句?
How do I write the above select statement in CodeIgniter active record?
推荐答案
- >其中()
支持将任何字符串传递给它,
->where()
support passing any string to it and it will use it in the query.
您可以尝试使用:
$this->db->select('*')->from('certs');
$this->db->where('`id` NOT IN (SELECT `id_cer` FROM `revokace`)', NULL, FALSE);
,NULL,FALSE
code> where()告诉CodeIgniter不要转义查询,这可能会导致错误。
The ,NULL,FALSE
in the where()
tells CodeIgniter not to escape the query, which may mess it up.
UPDATE :您也可以查看我写的子查询库。
$this->db->select('*')->from('certs');
$sub = $this->subquery->start_subquery('where_in');
$sub->select('id_cer')->from('revokace');
$this->subquery->end_subquery('id', FALSE);
这篇关于codeigniter活动记录中的子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文