2015-12-04 84 views
0

有人可以指出我們在下面的查詢中出了什麼問題嗎?我有3張桌子。加入SQL語法錯誤

1. Order Header - Order_header_id 
2. Order Pricelist - order_header_id(fk),pricelist_id(fk) 
3. Pricelist - pricelist_id,Name 

我試圖讓基於使用下面的查詢訂單頭價格表名稱,並將其拋出「缺少右括號」的錯誤。不知道我是否在正確的方向。

Select pricelist.Name from ORDER_HEADER 
left outer join 
(select order_pricelist.pricelist_id from order_pricelist on order_header.order_header_id = order_pricelist.order_header_id 
left outer join 
(select pricelist.name from pricelist) pricelist on order_pricelist.pricelist_id = pricelist.pricelist_id) 

感謝

+0

之前,你的第二個「你mssing一個右括號左外連接「 - 正如錯誤所述!此外,你應該有一個別名,就像你爲第二次加入一樣。 –

回答

0
Select pricelist.Name from ORDER_HEADER 
left outer join 
(select pricelist_id, order_header_id from order_pricelist) op 
    ON order_header.order_header_id = op.order_header_id 
left outer join 
(select name,pricelist_id from pricelist) pr 
    ON op.pricelist_id = pr.pricelist_id 

但實際上,你並不需要在這裏的子查詢,所以它可以是這樣的:

Select pricelist.Name from ORDER_HEADER 
left outer join order_pricelist op on order_header.order_header_id = op.order_header_id 
left outer join pricelist pr on op.pricelist_id = pr.pricelist_id