简体   繁体   English

联接3个表时无法查看结果

[英]Can't View result while joining 3 tables

I have some trouble when I Joining 3 tables, I use mysqli procedural. 我在加入3个表时遇到麻烦,我使用mysqli程序。 here's my query.. 这是我的查询。

$select = $connection->conn->query('SELECT * FROM master_beli, supplier, karyawan WHERE supplier.id_supplier = master_beli.id_supplier AND karyawan.id_karyawan = master_beli.id_karyawan');

After that I viewing with this code 之后,我用这段代码查看

while($fetchData = $select->fetch_array()){
   echo $fetchData['id_karyawan'].'<br>';
}

I don't know where the problem is, because I use this query a few months ago and it's worked, but now isn't work.. 我不知道问题出在哪里,因为几个月前我使用了此查询并且它已经工作了,但现在却行不通。

SELECT  master_beli.id_supplier,master_beli.id_karyawan
 FROM master_beli
 join supplier  on supplier.id_supplier = master_beli.id_supplier
 join karyawan on karyawan.id_karyawan = master_beli.id_karyawan;

it work on mysql 它在mysql上工作

Could be your issue is related to the ambiguity of the column name id_karyawan present in two tables try use an explicit alias or a explict column naming eg : 可能是您的问题与两个表中存在的列名id_karyawan的歧义有关,请尝试使用显式别名或显式列命名,例如:

$select = $connection->conn->query('SELECT master_beli.id_karyawan
      FROM master_beli
      INNER JOIN supplier ON supplier.id_supplier = master_beli.id_supplier 
      INNER JOIN karyawan ON  karyawan.id_karyawan = master_beli.id_karyawan');

and as suggested in the code above you should use explicit join sintax ..for better readibilty (the use of implict join sintax is not more promoted in sql) 并按照上面的代码中的建议,您应该使用显式联接sintax ..以获得更好的可读性(在SQL中不提倡使用隐式联接sintax)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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