我想在mysql数据库中获取逗号分隔的记录

我想在mysql数据库中获取逗号分隔的记录,mysql,sql,select,in-operator,find-in-set,Mysql,Sql,Select,In Operator,Find In Set,在我的数据库表中,我有6列idauto、title、news、image和type 我写这个查询 select id,title,image from add_news where FIND_IN_SET('Travel','Music',type) ORDER BY id DESC 我得到了这个错误 Incorrect parameter count in the call to native function 'FIND_IN_SET' 在运算符中使用,而不是在集合中查找 试试这个

在我的数据库表中,我有6列idauto、title、news、image和type 我写这个查询

select id,title,image 
from add_news 
where FIND_IN_SET('Travel','Music',type) 
ORDER BY id DESC
我得到了这个错误

Incorrect parameter count in the call to native function 'FIND_IN_SET'
在运算符中使用,而不是在集合中查找

试试这个:

SELECT A.id, A.title, A.image 
FROM add_news A
WHERE A.type IN ('Travel', 'Music')
ORDER BY A.id DESC
在运算符中使用,而不是在集合中查找

试试这个:

SELECT A.id, A.title, A.image 
FROM add_news A
WHERE A.type IN ('Travel', 'Music')
ORDER BY A.id DESC
我猜该类型是一个逗号分隔的列表。这是一种非常糟糕的数据格式,您应该有一个单独的表,每个类型和文章有一行

但是,给定格式,正确的语法是:

select id, title, image
from add_news
where find_in_set('Travel', type) > 0 or
      find_in_set('Music', type) > 0
order by id desc;
我猜该类型是一个逗号分隔的列表。这是一种非常糟糕的数据格式,您应该有一个单独的表,每个类型和文章有一行

但是,给定格式,正确的语法是:

select id, title, image
from add_news
where find_in_set('Travel', type) > 0 or
      find_in_set('Music', type) > 0
order by id desc;

错误很明显。即使是最粗略的谷歌搜索,也会为您带来该功能的文档:1。请参阅normalization。错误非常清楚。即使是最粗略的谷歌搜索,也会为您带来该功能的文档:1。参见规范化