Có thể lấy giá trị cột SET của MySQL dưới dạng danh sách offset nguyên nhờ hàm MAKE_SET(). Tạo bảng set_testing để minh họa:
mysql> CREATE TABLE set_testing(
id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
`table` SET('ABC','ABD','GHF') NOT NULL);
Query OK, 0 rows affected (0.08 sec)
mysql> INSERT INTO set_testing (`table`) VALUES('1');
Query OK, 1 row affected (0.06 sec)
mysql> INSERT INTO set_testing (`table`) VALUES('2');
Query OK, 1 row affected (0.06 sec)
mysql> INSERT INTO set_testing (`table`) VALUES('3');
Query OK, 1 row affected (0.02 sec)
mysql> INSERT INTO set_testing (`table`) VALUES('4');
Query OK, 1 row affected (0.02 sec)
mysql> SELECT * FROM set_testing;
+----+---------+
| id | table |
+----+---------+
| 1 | ABC |
| 2 | ABD |
| 3 | ABC,ABD |
| 4 | GHF |
+----+---------+
4 rows in set (0.00 sec)
Truy vấn lấy cột SET dưới dạng offset nguyên:
mysql> SELECT MAKE_SET(types+0,'1','2','3') AS output FROM doctypes1; +--------+ | output | +--------+ | 1 | | 2 | | 1,2 | | 3 | +--------+ 4 rows in set (0.00 sec)
Hàm MAKE_SET() chuyển đổi giá trị bit thành danh sách chuỗi tương ứng.