Reputation: 2785
I'm having trouble getting data from 3 tables using a join statement. I would appreciate any help.
Thanks.
I have 3 tables:
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"). For each appeal, to get all the fields in table "Appeals" and the Firstname and Lastname (from table "Users") that are related to SubmittedByUserID.
I wrote this SQL statement, but it's not working:
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
Please help!!! Thanks!!
Upvotes: 1
Views: 138
Reputation: 1612
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';
Upvotes: 1
Reputation: 1271003
MS Access has very specific syntax for joins, including specific keywords and parentheses. 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.
Upvotes: 2