【问题标题】:MySQL 'tahun_pemilihan' in where clause is ambigousMySQL 'tahun pemilihan' 在 where 子句中不明确
【发布时间】:2018-04-12 03:12:23
【问题描述】:

如何纠正我不断从下面的代码中得到的问题,该代码在子句不明确的地方声明“tahun_pemilihan”。提前感谢您的帮助。

这是 MySQL 表

 $sql = "SELECT 
              a.*, b.vektor_v FROM data_alternatif a, hasil b 
    WHERE a.id_alternatif=b.id_alternatif AND tahun_pemilihan='$thn'";

【问题讨论】:

    标签: mysql mysql-error-1052


    【解决方案1】:

    两个表都包含一个名为tahun_pemilihan 的列,因此在WHERE 子句条件中,不清楚要使用哪个表的列;它应该使用来自data_alternatif 还是来自结果表hasil 的那个?

    如果应该使用列data_alternatif.tahun_pemilihan,则使用a.tahun_pemilihan='$thn' 限定WHERE 子句中的表;如果要使用hasil.tahun_pemilihan,则使用b.tahun_pemilihan='$thn'

    【讨论】:

      【解决方案2】:

      如果列名存在于您连接的两个表中,您可能会遇到列名不明确的错误。

      在您的情况下,列名tahun_pemilihan 存在于您的两个表中。

      解决方案:

      选择您将使用的两个表中的哪一个。 a.tahun_pemilihan='$thn'b.tahun_pemilihan='$thn'

      https://www.quora.com/What-does-the-SQL-ambiguous-column-name-error-mean

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-05-30
        • 2010-09-25
        • 1970-01-01
        • 2018-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-07
        相关资源
        最近更新 更多