资讯专栏INFORMATION COLUMN

【mysql】[error]group_concat造成的sql语法错误

littleGrow / 3456人阅读

摘要:错误实例完整错误原因中多了一个逗号执行结构有大小限制,会根据大小进行截取参考手册

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大小进行截取

参考:mysql手册-group_concat

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/30436.html

相关文章

发表评论

0条评论

littleGrow

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<