[英]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.我如何纠正我从下面的代码中得到的问题,该代码在子句不明确的地方声明了“tahun_pemilihan”。 Thanks for the help in advance.
提前感谢您的帮助。
here is the MySQL table这是 MySQL 表
$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;两个表都包含一个名为
tahun_pemilihan
的列,因此在WHERE
子句条件中不清楚要使用哪个表的列; should it use the one from data_alternatif
or from the results table hasil
?应该用它从一个
data_alternatif
或从结果表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.限定表中
WHERE
与任一条款a.tahun_pemilihan='$thn'
是否应该使用列data_alternatif.tahun_pemilihan
或b.tahun_pemilihan='$thn'
如果hasil.tahun_pemilihan
是一个使用。
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.在您的情况下,列名
tahun_pemilihan
存在于您的两个表中。
Solution:解决方法:
Pick which one of the two table you will use.选择您将使用的两个表中的哪一个。
a.tahun_pemilihan='$thn'
or b.tahun_pemilihan='$thn'
a.tahun_pemilihan='$thn'
b.tahun_pemilihan='$thn'
a.tahun_pemilihan='$thn'
或b.tahun_pemilihan='$thn'
https://www.quora.com/What-does-the-SQL-ambiguous-column-name-error-mean https://www.quora.com/What-does-the-SQL-ambiguous-column-name-error-mean
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.