[英]Not unique table/alias: 'products'
嗨,大家好,这是我第一次处理内部联接,因此非常感谢您的帮助。
JUst想知道为什么我从创建的代码中得到以下错误:
不是唯一的表格/别名:“产品”
这是代码本身:
mysql_select_db($database_reps, $reps);
$query_orders = sprintf("SELECT
orders.ID AS mainID,
customers.`Name` AS customerName,
products.ProductName AS product,
orders.Quantity AS Quantity,
orders.comment As comment,
orders.SalesPrice AS SalesPrice,
orders.Price AS Price,
orders.paid AS paid,
orders.product2 AS product2,
orders.AgeOfPayment AS AgeOfPayment,
orders.orderDate AS orderDate,
products.Price AS productPrice,
staff.StaffName AS staffMember,
orders.bonus AS bonus
FROM
orders
INNER JOIN staff AS staff ON orders.staffMember = staff.ID
INNER JOIN products AS products ON orders.product = products.ID
INNER JOIN products AS products ON orders.product2 = products.ID
INNER JOIN customers AS customers ON orders.customerName = customers.ID
WHERE
orders.ID = %s", GetSQLValueString($colname_orders, "int"));
$orders = mysql_query($query_orders, $reps) or die(mysql_error());
$row_orders = mysql_fetch_assoc($orders);
$totalRows_orders = mysql_num_rows($orders);
加入证明有点困难,但是任何帮助都值得赞赏。
INNER JOIN products AS products ON orders.product = products.ID
INNER JOIN products AS products ON orders.product2 = products.ID
两个连接到products
正在别名为表products
,使用对于每个像不同的别名products1
和products2
; 并确保在所选列的列表中使用正确的别名; 尽管您的选择列表并没有真正表明您要引用的内容
编辑
SELECT orders.ID AS mainID,
customers.`Name` AS customerName,
products1.ProductName AS productName1,
products2.ProductName AS productName2,
orders.Quantity AS Quantity,
orders.comment As comment,
orders.SalesPrice AS SalesPrice,
orders.Price AS Price,
orders.paid AS paid,
orders.product2 AS product2,
orders.AgeOfPayment AS AgeOfPayment,
orders.orderDate AS orderDate,
products1.Price AS productPrice1,
products2.Price AS productPrice2,
staff.StaffName AS staffMember,
orders.bonus AS bonus
FROM orders
INNER JOIN staff
ON orders.staffMember = staff.ID
INNER JOIN products AS products1
ON orders.product = products1.ID
INNER JOIN products AS products2
ON orders.product2 = products2.ID
INNER JOIN customers
ON orders.customerName = customers.ID
WHERE orders.ID = ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.