Looking for an exact match in a set column : Set « Data Types « MySQL Tutorial






Comparing set values to 'val1,val2' returns different results than comparing values to 'val2,val1'.

mysql>
mysql>
mysql> SELECT * FROM tbl_name WHERE set_col = 'val1,val2';
mysql>
mysql>
mysql> CREATE TABLE myset (col SET('a', 'b', 'c', 'd'));
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO myset (col) VALUES ('a,d'),
    ->                                ('d,a'),
    ->                                ('a,d,a'),
    ->                                ('a,d,d'),
    ->                                ('d,a,d');
Query OK, 5 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  |
+------+
5 rows in set (0.00 sec)

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

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








10.19.Set
10.19.1.SET Type
10.19.2.SET column type
10.19.3.Using the SET type
10.19.4.If you set a SET column to an unsupported value, the value is ignored and a warning is issued
10.19.5.Search for SET values using the FIND_IN_SET() function
10.19.6.Search for SET values using the LIKE operator
10.19.7.Looking for values containing the first set member
10.19.8.MySQL stores SET and ENUM as numbers
10.19.9.Looking for an exact match in a set column