我遇到了 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()
您可以使用
where
来代替并在那里构造您的 IN
子句:
$this->db->where('lookbook_id IN (SELECT lookbook_id FROM shopify_point WHERE point_id = $pointid)', NULL, FALSE);