Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match 2 out of "1,2,7,9,13,3,10,4,21,6,12" in MySQL?

Tags:

regex

mysql

I'm not familiar with regex in MySQL.

like image 737
user198729 Avatar asked Dec 12 '25 00:12

user198729


1 Answers

For testing if the value exists in the string you can use

mysql> SELECT FIND_IN_SET(15, '1,2,15,4,5,6');
+---------------------------------+
| FIND_IN_SET(15, '1,2,15,4,5,6') |
+---------------------------------+
|                               3 |
+---------------------------------+
1 row in set (0.00 sec)

and test it for greater than 0 (0 is returned if no match is found).

like image 151
Tor Valamo Avatar answered Dec 13 '25 14:12

Tor Valamo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!