Utku Dalmaz
Utku Dalmaz

Reputation: 10162

finding a row which has several ids separated by comma MYSQL

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?

Upvotes: 3

Views: 70

Answers (2)

Imdad
Imdad

Reputation: 6032

Yes, FIND_IN_SET in one way.

Another way is

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

Upvotes: 0

Mark Byers
Mark Byers

Reputation: 838116

Yes, you can use FIND_IN_SET:

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

Upvotes: 4

Related Questions