Multiple LIKE in SQL

I wanted to search across multiple lines and get a line containing a specific item.

The table in mySQL is configured so that each identifier has a unique list (comma-delimited) of the values ​​in the row.

Example:

id | order
1  | 1,3,8,19,34,2,38
2  | 4,7,2,190,38

Now, if I wanted to pull out a line containing only number 19, how would I do it? The possibilities that I could see in a list with a LIKE condition would be the following:

19,     <-- 19 at the start of the list
,19     <-- 19 at the end of the list
,19,    <-- 19 inside the list

I tried the following and I can not get any results, thanks for your help!

SELECT *
FROM categories
WHERE order LIKE '19,%' OR '%,19%' OR '%,19%'
LIMIT 0 , 30
+3
source share
2 answers

You can use FIND_IN_SETto solve your problem in a simpler way:

SELECT *
FROM categories
WHERE FIND_IN_SET('19', `order`)
LIMIT 0, 30

, , .

+6

, , , .

, :

WHERE ',' + order + ',' LIKE '%,19,%'

order, , , .

, , , , OR LIKE, , , SQL :

WHERE order LIKE '19,%' OR order LIKE '%,19,%' OR order LIKE '%,19'
                           ---+------      ^     ----+-----       ^
                              |            |         |            |
                              +- add this -+---------+            +- removed
                                                                     percent

, , 19, , , 19.

+7

Source: https://habr.com/ru/post/1747783/


All Articles