我有一个类似的查询
select prod_name
from ct_products
where id in ( (select prod_id
from ct_recommend
where cat_id=12) ) and status > 0
但是,由于子查询返回看起来像 1,2,3 的字符串而不是结果行,因此查询无法按应有的方式工作。有没有办法格式化子查询结果,使其在 IN 子句中工作?
谢谢!
最佳答案
尝试一下,
select prod_name
from ct_products
where FIND_IN_SET(ID,(select prod_id from ct_recommend where cat_id=12)) <> 0
and status > 0
关于来自子查询的 MySQL IN 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13775487/