前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >联表查询时,相同字段未取别名导致报错(mysql)

联表查询时,相同字段未取别名导致报错(mysql)

作者头像
botkenni
发布2019-09-02 16:28:05
4.1K0
发布2019-09-02 16:28:05
举报
文章被收录于专栏:IT码农IT码农IT码农

Integrity constraint violation – yii\db\IntegrityException

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'company_id' in where clause is ambiguous The SQL being executed was: SELECT COUNT(*) FROM `crm_customer` LEFT JOIN `crm_customer_combine` `cc` ON `crm_customer`.`id` = `cc`.`customer_id` WHERE (`company_id`=11) AND ((`cc`.`level`=1) AND (`cc`.`administrator_id`=1))

Error Info: Array
(
    [0] => 23000
    [1] => 1052
    [2] => Column 'company_id' in where clause is ambiguous
)

Caused by: PDOException

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'company_id' in where clause is ambiguous

出现相同的字段报错:SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'company_id' in where clause is ambiguous

解决:取别名

$query = MysqlTableName::find()->alias('c');
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Integrity constraint violation – yii\db\IntegrityException
    • SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'company_id' in where clause is ambiguous The SQL being executed was: SELECT COUNT(*) FROM `crm_customer` LEFT JOIN `crm_customer_combine` `cc` ON `crm_customer`.`id` = `cc`.`customer_id` WHERE (`company_id`=11) AND ((`cc`.`level`=1) AND (`cc`.`administrator_id`=1))
      • Caused by: PDOException
        • SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'company_id' in where clause is ambiguous
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档