A
A
Alexey2015-11-29 23:24:45
MySQL
Alexey, 2015-11-29 23:24:45

How to find a number using LIKE?

Hello everyone, there is a table of approximately the following structure:
5ee72214f3b74bcaaa9d474720bd9274.jpg
All numbers are separated by a comma. How can I extract, for example, records where there is a number 1 in?
But it should be exactly a number and not a figure, i.e. the number 17 does not fit. I try this way, and everything seems to work out, but is it right, won’t some conditions appear later under which the number 17 or, say, 119 or something else will be pulled out?

SELECT * FROM `table` WHERE number = 1 OR number LIKE ',1' OR number LIKE '1,' OR number LIKE ',1,'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aleksey Ratnikov, 2015-11-30
@dzheka3d

FIND_IN_SET() to help you:

SELECT * FROM table_name WHERE FIND_IN_SET(1, numbers) IS NOT NULL

M
Melkij, 2015-11-29
@melkij

Get it back to normal. Immediately the mountain of crutches will disappear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question