我有以下查询
SELECT * FROM table WHERE id IN (5,4,3,1,6)
我想再次从SELECT中获得该值“ 5,4,3,1,6”。
SELECT * FROM table WHERE id IN (SELECT popuplarList FROM Settinng WHERE id =1 )
但是我只得到5号帖子。我想从“ 5,4,3,1,6”中获取所有帖子。
是否可以通过其他逻辑或其他方式解决此问题?
非常感谢
答案 0 :(得分:3)
尝试FIND_IN_SET方法
SELECT * FROM table WHERE FIND_IN_SET(id, (SELECT popuplarList FROM Settinng WHERE id =1 ))
答案 1 :(得分:1)
请尝试以下操作:
select *
from table
where (
select CONCAT(",", popuplarList, ",")
from Settinng where id = 1
) like concat("%,", id, ",%")
select * from table WHERE FIND_IN_SET(`id`, (
select CONCAT(",", popuplarList, ",") from Settinng where id = 1)
)