[英]PHP error on joining table says not unique table or alias
I don't know how to fix this thing a little help would be good. 我不知道如何解决这个问题,一点点帮助将是很好的。
Error : table/alias is not unique. 错误:表/别名不是唯一的。
Why do i got this error? 为什么会出现此错误? I believe why joins are correct.Please help 我相信加入的原因是正确的。请帮助
$q = "SELECT * FROM `curriculum` "
. "INNER JOIN `subject` ON `curriculum`.`subject`=`subject`.`sub_id` "
. "LEFT JOIN `subject` ON `curriculum`.`cur_pr`=`subject`.`sub_id` "
. "WHERE `course`=:cid and `cur_year`=1";
Change your Code to 将您的代码更改为
$q = "SELECT * FROM `curriculum` AS A "
. "INNER JOIN `subject` AS B ON `A`.`subject`=`B`.`sub_id` "
. "LEFT JOIN `subject` AS C ON `A`.`cur_pr`=`C`.`sub_id` "
. "WHERE `course`=:cid and `cur_year`=1";
If you want to join Same tables again use Table Aliases
Here AS
is used to this purpose 如果你想加入相同的表再次使用Table Aliases
这里AS
用于此目的
You get an error that says table/alias is not unique because this line code: 您会收到一条错误消息,指出表/别名不是唯一的,因为此行代码:
. 。 "LEFT JOIN
subject
ONcurriculum
.cur_pr
=subject
.sub_id
" “curriculum
加入LEFT JOINsubject
cur_pr
=subject
sub_id
”
It don't know what subject is belong to what table ( first one or the second one). 它不知道哪个主题属于哪个表(第一个表或第二个表)。 You can try this code above 您可以在上面尝试此代码
$q = "SELECT * FROM `curriculum` AS cu "
. "INNER JOIN `subject` AS su1 ON `cu`.`subject`=`su1`.`sub_id` "
. "LEFT JOIN `subject` AS su2 ON `cu`.`cur_pr`=`su2`.`sub_id` "
. "WHERE `cu.course`=:cid and `cu.cur_year`=1";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.