2010-08-14 8 views
1

我想LEFT OUTER JOIN兩個表,然後一起INNER JOIN另一個表在Access 2007加入3個表到1 - SQL

SELECT RestaurantName, 
      StreetAddress, 
      City, 
      State, 
      Zip, 
      RestaurantWebsite, 
      MenuLink, 
      RestaurantTimes, 
      PhoneNumber, 
      PictureTitle, 
      PictureTitle3, 
      PictureTitle3, 
      PictureTitle4, 
      PictureTitle, 
      TagType 
     FROM Restaurants r 
LEFT OUTER JOIN RestaurantPictures rp ON r.ID = rp.ID 
INNER JOIN RestaurantTag rt ON r.TagID = t.TagID 

我不斷收到一個語法錯誤在我的查詢表達式。 「INNER JOIN RestaurantTag rt ON rt.TagID = r.TagID」

我在Restaurant和RestaurantTag表中都有一個對應的TagID。我似乎無法弄清楚爲什麼我得到這個錯誤。我可以成功地加入前兩個表,但第三個表是給我的麻煩。任何建議將不勝感激!

回答

2

沒有看到表的定義,這是一個猜測,但你有一個錯誤:

INNER JOIN RestaurantTag rt ON r.TagID = t.TagID應該INNER JOIN RestaurantTag rt ON r.TagID = rt.TagID

+0

+1:你是第一個 – 2010-08-14 03:05:10

+0

好眼睛。我糾正了這一點,並且還添加了()第一條語句,並且它工作正常。感謝您的幫助。 – nikl91 2010-08-14 03:16:06

+0

@OMG小馬:僅僅是因爲答案框在IE8中廢話! ;) – 2010-08-14 03:18:26

0
SELECT 
    RestaurantName, StreetAddress, City, State, Zip, RestaurantWebsite, 
    MenuLink, RestaurantTimes, PhoneNumber, PictureTitle, PictureTitle3, 
    PictureTitle3, PictureTitle4, PictureTitle, TagType 
FROM 
    Restaurants r LEFT OUTER JOIN RestaurantPictures rp ON r.ID = rp.ID 
    INNER JOIN RestaurantTag rt ON r.TagID = rt.TagID 
1

嘗試把在聯接表達式()

(Restaurants r LEFT OUTER JOIN RestaurantPictures rp ON r.ID = rp.ID) 
INNER JOIN RestaurantTag rt ON r.TagID = t.TagID 
+0

這是贏家。謝謝您的幫助! – nikl91 2010-08-14 03:15:33