2017-07-22 3 views
-2

Ich kann den Fehler nicht in MYSQL Syntax finden:MySql Syntaxfehler (Joins)

"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";" 

Fehler sind unter 1064 - Sie haben einen Fehler in Ihrer SQL-Syntax; Überprüfen Sie das Handbuch, das Ihrer MariaDB-Serverversion entspricht, für die richtige Syntax in der Nähe von 'ON orderlist.OrderCode = orderdetail.OrderCode' ON product.ProductCode = orderde 'at line 1

+0

'INNER JOIN (Bestelliste INNER JOIN (orderdetail' usw. ist ungültig Syntax, wie der Fehler sagt Die richtige Syntax lautet' INNER JOIN. ON = INNERER JOIN ON = '. Suchen Sie nach einem SQL-Lernprogramm oder -Buch (oder lesen Sie die MySQL-Dokumentation, genau wie in der Fehlermeldung angegeben) machen). –

Antwort

1

Schreiben Sie die Abfrage mit einer ON-Klausel, die jeweils folgt JOIN. Dies ist nur so viel einfacher zu lesen und schreiben und ist wahrscheinlich Ihr Problem:

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; 

Darüber hinaus ist die ORDER BY scheint überflüssig. Normalerweise würde es mit Aggregationsfunktionen verwendet werden. Wenn du irgendwie Duplikate bekommst (was unwahrscheinlich erscheint) benutze SELECT DISTINCT.

Schließlich Ich verstehe das nicht:

Where ol.OrderCode = @orderdetail.OrderCode 

Ich glaube nicht, @orderdetail.OrderCode gültige Syntax ist. Wenn Sie in einer Variablen übergeben wollen, wäre es wie folgt aussehen:

Where ol.OrderCode = @OrderCode