查找用逗号MYSQL分隔的具有多个id的行

时间:2022-06-14 00:19:17

data structure of the table is like that

表的数据结构是这样的

ID    ids
---   ----
 2    3432,545,65454
 3    654,3333223,54333
 4    547432

I want to find a row for example which has 545, what kinda query should i write? maybe find_in_set can help me?

我想找一个有545的行,我应该写什么样的查询呢?也许find_in_set可以帮助我?

2 个解决方案

#1


4  

Yes, you can use FIND_IN_SET:

是的,您可以使用FIND_IN_SET:

SELECT ID, ids
FROM yourtable
WHERE FIND_IN_SET('545', ids)

#2


0  

Yes, FIND_IN_SET in one way.

是的,FIND_IN_SET有一种方式。

Another way is

另一种方法是

select * from tablename
where  ids like '545'
OR ids like '545,%'
OR ids like '%,545'
OR ids like '%,545,%'

#1


4  

Yes, you can use FIND_IN_SET:

是的,您可以使用FIND_IN_SET:

SELECT ID, ids
FROM yourtable
WHERE FIND_IN_SET('545', ids)

#2


0  

Yes, FIND_IN_SET in one way.

是的,FIND_IN_SET有一种方式。

Another way is

另一种方法是

select * from tablename
where  ids like '545'
OR ids like '545,%'
OR ids like '%,545'
OR ids like '%,545,%'