Sets work in a similar way to enumerated fields
mysql>
mysql> CREATE TABLE test7 (fruit SET('apple','mango','litchi','banana'));
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> INSERT INTO test7 VALUES('banana');
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> INSERT INTO test7 VALUES('litchi');
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> INSERT INTO test7 VALUES('paw-paw');
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql>
The difference of a SET type is that you can add multiple instances:
mysql>
mysql> INSERT INTO test7 VALUES('apple,mango');
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> SELECT * FROM test7;
+-------------+
| fruit |
+-------------+
| banana |
| litchi |
| |
| apple,mango |
+-------------+
4 rows in set (0.00 sec)
mysql>
mysql>
mysql> INSERT INTO test7 VALUES('mango,apple');
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> SELECT * FROM test7 ORDER BY fruit;
+-------------+
| fruit |
+-------------+
| |
| apple,mango |
| apple,mango |
| litchi |
| banana |
+-------------+
5 rows in set (0.00 sec)
mysql>
mysql> drop table test7;
Query OK, 0 rows affected (0.00 sec)
Related examples in the same category