Search code examples
mysqlmysql-error-1052

MySQL 'tahun_pemilihan' in where clause is ambigous


How can I correct the problem I keep getting from the code below which states 'tahun_pemilihan' in where the clause is ambiguous. Thanks for the help in advance.

here is the MySQL table

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

Solution

  • Both tables contain a column named tahun_pemilihan so in the WHERE clause condition it is not clear which table's column to use; should it use the one from data_alternatif or from the results table hasil?

    Qualify the table in the WHERE clause with either a.tahun_pemilihan='$thn' if it should use column data_alternatif.tahun_pemilihan or b.tahun_pemilihan='$thn' if hasil.tahun_pemilihan is the one to use.