简体   繁体   中英

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'";

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.

You can encounter ambiguous column name error if the column name exist in both tables you have joined.

In your case, the column name tahun_pemilihan exist in both of your table.

Solution:

Pick which one of the two table you will use. a.tahun_pemilihan='$thn' or b.tahun_pemilihan='$thn'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM