asp.net - where 子句中的列 ' ' 不明确 mysql 中的错误

标签 asp.net mysql sql

SELECT tbl_user.userid,
       tbl_user.firstname,
       tbl_user.lastname,
       tbl_user.email,
       tbl_user.created,
       tbl_user.createdby,
       tbl_organisation.organisationname
FROM   tbl_user
       INNER JOIN tbl_organisation
         ON tbl_user.organisationid = tbl_organisation.organisationid
WHERE  organisationid = @OrganisationID;  

我正在使用此语句进行数据绑定(bind)。我在这里遇到错误。

where 子句中的“OrganisationID”列不明确

tbl_user 中的OrganisationID 与tbl_organisation 同名是错误的怎么办? OrganisationID 是来自 tbl_Organisation 的外键

最佳答案

因为在两个不同的表上有两个同名的列(这不是问题,在许多情况下甚至推荐这样做),您必须通知 MySQL 您要根据哪一个进行过滤。

在列名前添加表名(或别名,如果您使用表别名)。在你的情况下,要么

WHERE tbl_user.OrganisationID

WHERE tbl_Organisation.OrganisationID

应该可以。

关于asp.net - where 子句中的列 ' ' 不明确 mysql 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7517382/

相关文章:

c# - 将 SQL 表读入 C# DataTable

asp.net - 微软是否已证实他们对LINQ to SQL报废的立场?

php - Symfony2 与学说 : Nested conditions for findBy

mysql - 为什么 SQL 声明失败?

mysql - 将 CSV 导入 MySQL 数据库仅插入第一行

mysql - sh 脚本在 crontab 中不起作用

c# - ASP.NET - 如何获取 ContentPlaceHolder 中的 Div 控件?

javascript - 在 Internet Explorer Mobile 6 中播放声音

mysql - 处理选择查询mysql上的空值

mysql - 将多个 .sql 表转储文件合并到一个文件中