-1
我有這個疑問:如何做一個INNER JOIN查詢?
SELECT o.Date,
CONCAT (c.FirstName, '', c.LastName),
c.StreetAddress,
c.Apt,
c.City,
c.State,
c.ZipCode,
c.HomePhone,
c.MobilePhone,
c.OtherPhone,
i.Quantity,
d.DonutName,
d.Description,
d.UnitPrice,
o.Notes,
FROM Customer AS c,
DonutOrder AS o,
OrderLineItem AS i,
Donut AS d
INNER JOIN DonutOrder AS o ON c.CustomerID = o.CustomerID
INNER JOIN Donut AS d ON o.DonutOrderID = i.DonutOrderID
INNER JOIN OrderLineItem AS i ON d.DonutID = i.DonutID
;
我收到此錯誤:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM Customer AS c, DonutOrder AS o, OrderLineItem AS i, Donut AS d INN' at line 16.
有什麼不對?
這裏是鏈接到我的SQL小提琴頁:http://sqlfiddle.com/#!9/a2842/7
是的,我確實意味着訂購日期!感謝您在我的選擇結束時注意到額外的逗號。我甚至沒有想到我的OrderLineItem表中沒有數據。那麼在查詢中沒有必要呢? –
那麼,這取決於你在輸出中想要什麼。正如您現在所見,您需要'OrderLineItem'表中的數據,因爲您從中選擇數量。這完全取決於你想要輸出什麼,以防在那裏沒有數據。也許你想要執行一個外部連接......讓你來決定。 – trincot
我刪除了OrderLineItem及其所有語句,然後在我的Select語句中添加了DonutID和DonutOrderID,現在我收到錯誤:'on子句'中的未知列'c.CustomerID' –