“SELECT ... IN(SELECT ...)”在CodeIgniter中查询 [英] "SELECT ... IN (SELECT ...)" query in CodeIgniter

查看:249
本文介绍了“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中查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆