本文介绍了“SELECT ... IN(SELECT ...)”在CodeIgniter中查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有类似这样的查询:
SELECT username FROM users WHERE locationid IN (SELECT locationid FROM locations WHERE countryid='$')
如何在CodeIgniter中运行此查询?我无法在CodeIgnite的用户指南中找到解决方案。
How could I run this query in CodeIgniter? I can't find a solution in CodeIgnite's user guide.
非常感谢您的回答!
尊敬的!
推荐答案查看这里。
基本上你必须做绑定参数:
Basically you have to do bind params:
$sql = "SELECT username FROM users WHERE locationid IN (SELECT locationid FROM locations WHERE countryid=?)"; $this->db->query($sql, '__COUNTRY_NAME__');但是,和E先生说的一样,使用连接:
But, like Mr.E said, use joins:
$sql = "select username from users inner join locations on users.locationid = locations.locationid where countryid = ?"; $this->db->query($sql, '__COUNTRY_NAME__');更多推荐
“SELECT ... IN(SELECT ...)”在CodeIgniter中查询
发布评论