[英]Integrity constraint violation: 1052 Column 'group_id' in where clause is ambiguous
I'm trying to do inner join for groups table and status table but it stated this error:我正在尝试对组表和状态表进行内部连接,但它说明了这个错误:
Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'group_id' in where clause is ambiguous in C:\xampp\xampp\htdocs\mindspace\libs\database.php:27 Stack trace: #0 C:\xampp\xampp\htdocs\mindspace\libs\database.php(27): PDOStatement->execute(Array) #1 C:\xampp\xampp\htdocs\mindspace\Business Services Layer\ManageGroupsModel\GroupsModel.php(36): DB::run('select status.s...', Array) #2 C:\xampp\xampp\htdocs\mindspace\Business Services Layer\ManageGroupsController\GroupsController.php(40): ManageGroupsModel->displayStatus() #3 C:\xampp\xampp\htdocs\mindspace\Application Layer\ManageGroupsView\view_group.php(13): ManageGroupsController->displayStatus('12') #4 {main} thrown in C:\xampp\xampp\htdocs\mindspace\libs\database. Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'group_id' in where clause is ambiguous in C:\xampp\xampp\htdocs\mindspace\libs\database.php:27 Stack trace: #0 C :\xampp\xampp\htdocs\mindspace\libs\database.php(27): PDOStatement->execute(Array) #1 C:\xampp\xampp\htdocs\mindspace\Business Services Layer\ManageGroupsModel\GroupsModel.php(36 ): DB::run('select status.s...', Array) #2 C:\xampp\xampp\htdocs\mindspace\Business Services Layer\ManageGroupsController\GroupsController.php(40): ManageGroupsModel->displayStatus( ) #3 C:\xampp\xampp\htdocs\mindspace\Application Layer\ManageGroupsView\view_group.php(13): ManageGroupsController->displayStatus('12') #4 {main} 在 Z0D61F8370CAD1D412F80B84D143E1257 中抛出\mindspace\libs\数据库。 php on line 27 php 上线 27
function displayStatus() {
$sql = "select status.status_content, groups.group_name from status inner join groups on status.group_id = groups.group_id where group_id=:group_id";
$args = [':group_id'=>$this->group_id];
return DB::run($sql, $args);
}
Can anyone please help me cause I'm not sure which part did I do wrongly.谁能帮助我,因为我不确定我做错了哪一部分。
You've got two group_id
fields in your results.您的结果中有两个group_id
字段。 mySQL isn't sure which one you want to test in your WHERE
clause. mySQL 不确定您要在WHERE
子句中测试哪一个。 You need to specify it using the correct alias (as you've done in the JOIN already).您需要使用正确的别名指定它(就像您在 JOIN 中所做的那样)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.