Search for SET values using the FIND_IN_SET() function : Set : Data Types MySQL TUTORIALS


MySQL TUTORIALS » Data Types » Set »

 

Search for SET values using the FIND_IN_SET() function


SELECT FROM tbl_name WHERE FIND_IN_SET('value',set_col)>0;
mysql>
mysql>
mysql> CREATE TABLE myset (col SET('a''b''c''d'));
Query OK, rows affected (0.01 sec)

mysql> INSERT INTO myset (colVALUES ('a,d'),
    ->                                ('d,a'),
    ->                                ('a,d,a'),
    ->                                ('a,d,d'),
    ->                                ('d,a,d');
Query OK, rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT col FROM myset;
+------+
| col  |
+------+
| a,d  |
| a,d  |
| a,d  |
| a,d  |
| a,d  |
+------+
rows in set (0.00 sec)

mysql>
mysql> select from myset where find_in_set('a', col0;
+------+
| col  |
+------+
| a,d  |
| a,d  |
| a,d  |
| a,d  |
| a,d  |
+------+
rows in set (0.00 sec)

mysql>
mysql> drop table myset;
Query OK, rows affected (0.00 sec)

mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Data Types
» Set