MySql 之 FIND_IN_SET 和IN
2015-08-22 17:15
597 查看
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)
`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)
相关文章推荐
- Azure中的WEB项目与Azure的MySQL连接
- xtrabackup与mysqldump对比测试
- 14款经典的MySQL客户端软件
- 14款经典的MySQL客户端软件
- XtraBackup 实现不停机不锁表搭建mysql主从
- mysql 数据表的基本操作
- MySQL必知必会(正则表达式)
- mysqldump工具的使用
- MySQL必知必会(通配符过滤Like,%,_)
- MySQL必知必会(组合Where子句,Not和In操作符)
- MySQL索引与优化
- Mysql修改设置root密码的命令及方法
- mysql
- 创建了远程账号仍然无法远程mysql的问题
- 报错:1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost
- MYSQL自动写入当前时间。
- 反射ORM 三层(for sql server/mysql)
- Mysql基础
- MySQL installer
- MySQL installer