使用 CodeIgniter 的 where_in() 方法在子查询中选择 WHERE

问题描述 投票:0回答:1

我遇到了 where_in 的问题。我正在尝试获取拥有特定点 id 的 Lookbook 的商店名称

$this->db->select('shop');
$this->db->from('shopify_lookbook');
$this->db->where_in(
    'lookbook_id',
    'SELECT lookbook_id
     FROM shopify_point
     WHERE point_id = $pointid'
);

问题是它生成的查询

SELECT `shop` FROM `shopify_lookbook` WHERE `lookbook_id` IN('SELECT lookbook_id FROM shopify_point WHERE point_id = 543') 

它将给出空白,但是当我尝试在 mysql 中不使用

IN()
中的“”时,如下所示

SELECT `shop`
FROM `shopify_lookbook`
WHERE `lookbook_id` IN(
    SELECT lookbook_id
    FROM shopify_point
    WHERE point_id = 543
)

它返回我想要的商店名称。如何删除

''
中的
$this->db->where_in()

php codeigniter query-builder where-in in-subquery
1个回答
1
投票

您可以使用

where
来代替并在那里构造您的
IN
子句:

$this->db->where('lookbook_id IN (SELECT lookbook_id FROM shopify_point WHERE point_id = $pointid)', NULL, FALSE);
© www.soinside.com 2019 - 2024. All rights reserved.