简体   繁体   English

不是唯一的表/别名股票:

[英]Not a unique table/alias stock:

Ive got the query below : 我有以下查询:

$sql = "SELECT `scanners`.`KordNo`, `scanners`.`BundleNumber`
  FROM `scanners`, `TWOrder`, `Stock`
  INNER JOIN `TWORDER` ON `scanners`.`KordNo` = `TWOrder`.`KOrdNo`
  AND `scanners`.`Date` = '" . $date . "'
  INNER JOIN `Stock`  ON `TWOrder`.`Product` =`Stock`.`ProductCode`
  AND `Stock`.`ProductGroup` NOT BETWEEN 400 AND 650  
  AND `scanners`.`Scanner` IN (
  ORDER BY `scanners`.`KordNo` ASC";
  foreach($scanner as $x) 
  {$sql .= $x . ",";}
   $sql .= "0);";
  // And query the database
  $result = mysql_query($sql);
  while($row = mysql_fetch_array($result))
  $return[] = $row;
}

When i echo the sql on php my admin i get the error not a unique table/alias stock; 当我回复php上的sql我的管理员我得到错误不是一个独特的表/别名股票;

can someone advise? 有人可以建议吗?

Since you're using explicit JOINs, drop the other two tables off of the FROM clause. 由于您使用的是显式JOIN,因此请从FROM子句中删除其他两个表。

...
FROM `scanners`
INNER JOIN `TWORDER` ON `scanners`.`KordNo` = `TWOrder`.`KOrdNo`
...

On line 2 you have... 在第2行你有......

FROM `scanners`, `TWOrder`, `Stock`

Then you have some INNER JOINs on to TWOrder and Stock. 然后你有一些INNER JOINs到TWOrder和Stock。

  1. That's mixing syntax ( , and JOIN ) which is messy. 这就是混合语法( ,JOIN ),这是凌乱。 Stick to JOIN 坚持JOIN
  2. It means that TWOrder and Stock are mentioned Twice in the query 这意味着在查询中提到TWOrder和Stock两次

If you REALLY need to include those table multiple times in one query, you need to give them alias names, so they can be distiguished from each other. 如果您真的需要在一个查询中多次包含这些表,则需要为它们指定别名,以便它们可以相互分离。

But I think it's probably a mistake and that Line 2 should just be 但我认为这可能是一个错误,第2行应该是

FROM `scanners`


Then, also, I'm not sure how you got that to compile. 然后,我也不确定你是如何编译的。 You have IN ( and then an ORDER BY clause, to which you append a list of values. You should append the list before the ORDER BY and then append the ORDER BY after you've finished the loop. 你有IN (然后是一个ORDER BY子句,你追加一个值列表。你应该在ORDER BY之前追加列表,然后在完成循环后追加ORDER BY。

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

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