CREATE TABLE `test` (
  `id` int(8) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  `list` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
)
INSERT INTO `test` VALUES (1, 'name', 'daodao,xiaohu,xiaoqin');
INSERT INTO `test` VALUES (2, 'name2', 'xiaohu,daodao,xiaoqin');
INSERT INTO `test` VALUES (3, 'name3', 'xiaoqin,daodao,xiaohu');

mysql> select id, list, name from table where 'daodao' IN (list);


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'table
where 'daodao' IN (list)' at line 1

 

mysql> select * from test where find_in_set('daodao',list);
+----+-------+-----------------------+
| id | name | list |
+----+-------+-----------------------+
| 1 | name | daodao,xiaohu,xiaoqin |
| 2 | name2 | xiaohu,daodao,xiaoqin |
| 3 | name3 | xiaoqin,daodao,xiaohu |
+----+-------+-----------------------+
3 rows in set (0.00 sec)

 

 

 

相关文章:

  • 2021-06-09
  • 2022-12-23
  • 2021-09-15
  • 2021-05-30
  • 2022-01-16
  • 2022-12-23
猜你喜欢
  • 2021-08-03
  • 2021-08-23
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
相关资源
相似解决方案