将3个表连接成1 - SQL

时间:2010-08-14 02:57:48

标签: sql sql-server ms-access ms-access-2007

我正在尝试LEFT OUTER JOIN两个表,然后在Access 2007中INNER加入另一个表。

    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。我似乎无法弄清楚为什么我收到这个错误。我可以成功加入前两个表,但第三个表是给我带来麻烦的。任何建议将不胜感激!

3 个答案:

答案 0 :(得分:2)

没有看到表定义这是一个猜测,但是你有一个错误:

INNER JOIN RestaurantTag rt ON r.TagID = t.TagID应为INNER JOIN RestaurantTag rt ON r.TagID = rt.TagID

答案 1 :(得分:1)

尝试将连接表达式放在()

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

答案 2 :(得分: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