简体   繁体   English

MS-ACCESS 3表联接

[英]MS-ACCESS 3 table join

I'm having trouble getting data from 3 tables using a join statement. 我在使用join语句从3个表中获取数据时遇到麻烦。 I would appreciate any help. 我将不胜感激任何帮助。

Thanks. 谢谢。

I have 3 tables: 我有3张桌子:

Table "Users"
=============
UserID      FirstName   LastName
-----------------------------------------
1       Mick        Mickley
2       Tomy        Hanks
3       Roger       Waters


Table "Appeals"
===============
AppealID    Title       CategoryID  SubmittedByUserID
-----------------------------------------------------------------
1       Title1          2           1
2       Title2          2           1
3       Title3          3           2


And Table "AppealsCategories"
=============================
CatID       CatName     CatDescription
-----------------------------------------
1       CategoryA   CatDescription1
2       CategoryB   CatDescription2
3       CategoryC   CatDescription3

I want to be able to get all the appeals from table "Appeals", that have CategoryID that is related to Category name "CategoryA" (from table "AppealsCategories"). 我希望能够从表“ Appeals”中获取所有具有与类别名称“ CategoryA”相关的CategoryID的呼吁(从表“ AppealsCategories”)。 For each appeal, to get all the fields in table "Appeals" and the Firstname and Lastname (from table "Users") that are related to SubmittedByUserID. 对于每个上诉,要获取表“ Appeals”中的所有字段以及与SubmittedByUserID相关的名字和姓氏(来自表“ Users”)。

I wrote this SQL statement, but it's not working: 我写了这个SQL语句,但是不起作用:

SELECT Appeals.*, Users.Firstname, Users.LastName
FROM Users
JOIN Appeals ON Appeals.SubmittedByUserID=Users.UserID
JOIN AppealsCategories ON Appeals.CategoryID=AppealsCategories.CatID
WHERE AppealCategories.CatName='CategoryA';

Any help what I'm doing wrong..?? 任何帮助我做错了.. ?? I am using MS ACCESS 我正在使用MS ACCESS

Please help!!! 请帮忙!!! Thanks!! 谢谢!!

Like Paul also pointed, you have a typo in your query. 就像保罗也指出的那样,您的查询中有一个错字。 Also, brackets, lovely brackets that you need to wrap your joins into: 此外,还需要将联接包装到的方括号,可爱的方括号:

SELECT Appeals.*, Users.Firstname, Users.LastName
FROM ((Users
        JOIN Appeals ON Appeals.SubmittedByUserID=Users.UserID)
        JOIN AppealsCategories ON Appeals.CategoryID=AppealsCategories.CatID)
WHERE AppealsCategories.CatName='CategoryA';

MS Access has very specific syntax for joins, including specific keywords and parentheses. MS Access具有非常特殊的联接语法,包括特定的关键字和括号。 Try this: 尝试这个:

SELECT Appeals.*, Users.Firstname, Users.LastName
FROM (Users INNER JOIN
      Appeals
      ON Appeals.SubmittedByUserID = Users.UserID
     ) INNER JOIN
     AppealsCategories
     ON Appeals.CategoryID = AppealsCategories.CatID
WHERE AppealsCategories.CatName = "CategoryA";

Also the string delimiter is double quotes rather than single quotes. 字符串定界符也是双引号而不是单引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM