2017-07-22 63 views
-2

我找不到错误在MYSQL语法:MySQL的语法错误(使用连接)

"SELECT customer.CustomerCode, customer.CustomerName, customer.CustomerAddress, customer.CustomerHandphone, customer,CustomerEmail, product.ProductCode, product.ProductName, product.ProductPrice, orderdetail.OrderCode, orderdetail.ProductCode, orderdetail.ProductPrice, orderlist.OrderCode, orderlist.CustomerCode, orderlist.OrderPrice " + 
        "FROM customer INNER JOIN (product INNER JOIN (orderlist INNER JOIN(orderdetail INNER JOIN ON orderlist.OrderCode = orderdetail.OrderCode) ON product.ProductCode = orderdetail.ProductCode) ON customer.CustomerCode = orderlist.CustomerCode) " + 
        "Where orderlist.OrderCode [email protected] " + 
         "GROUP BY customer.CustomerCode, customer.CustomerName, customer.CustomerAddress, customer.CustomerHandphone, customer,CustomerEmail, product.ProductCode, product.ProductName, product.ProductPrice, orderdetail.OrderCode, orderdetail.ProductCode, orderdetail.ProductPrice, orderlist.OrderCode, orderlist.CustomerCode, orderlist.OrderPrice";" 

误差小于 1064 - 你在你的SQL语法错误;检查“ON product.ProductCode = orderde ON orderlist.OrderCode = orderdetail.OrderCode)”对应于您的MariaDB的服务器版本使用附近的正确语法手册第1行

+0

'INNER JOIN(orderlist INNER JOIN(orderdetail'等是无效的语法,就像错误说,正确的语法是'INNER JOIN。 ON = INNER JOIN ON = '。查找SQL教程或书籍(或者阅读MySQL文档,就像错误消息告诉你的一样去做)。 –

回答

1

ON条款下每个编写查询JOIN。这仅仅是这么容易读取和写入,并可能是您的问题:

SELECT c.CustomerCode, c.CustomerName, c.CustomerAddress, c.CustomerHandphone, c.CustomerEmail, 
     p.ProductCode, p.ProductName, p.ProductPrice, 
     od.OrderCode, od.ProductCode, od.ProductPrice, od.OrderCode, 
     ol.CustomerCode, ol.OrderPrice " + 
FROM orderlist ol INNER JOIN 
    orderdetail od 
    ON ol.orderCode = od.OrderCode INNER JOIN 
    customer c 
    ON c.CustomerCode = ol.CustomerCode INNER JOIN 
    product p 
    ON p.ProductCode = od.ProductCode; 

此外,ORDER BY似乎没有必要。通常它将与聚合功能一起使用。如果你以某种方式获得重复(这似乎不太可能)使用SELECT DISTINCT

最后,我不明白这一点:

Where ol.OrderCode = @orderdetail.OrderCode 

我不认为@orderdetail.OrderCode是有效的语法。如果你想在一个变量传递,它看起来更像是:

Where ol.OrderCode = @OrderCode