热线电话:13121318867

登录
2019-02-25 阅读量: 847
group_concat造成的sql语法错误

问题描述:

$sql_id = "select group_concat(`table_a_id`) from `table_b`";
$id_str = $db->execute($sql_id);

$sql = "select * from `table_a` where `id` in ( {$id_str} ) and `is_effect` = 1`";
$res = $db->execute($sql);

/*
error: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 ') and `is_effect` = 1'
*/
// 完整sql: select * from `table_a` where `id` in ( 1,2,3,4, ) and `is_effect` = 1`

解决方法:

sql中多了一个逗号

group_concat执行结构有大小限制,会根据byte大小进行截取

0.0000
0
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子