My table IncomingLetter has a foreign key to a table Department, which has an ID and a column Short_Name.
I’m using this query to count the incoming letters assigned to a department.
SELECT COUNT(DocumentNumber) AS TotalNumberIncomingLetters
FROM IncomingLetter
WHERE Assigned_To_Department=1;
Whereas this works I want to make a query based upon the short name and not based upon the ID.
SELECT COUNT(DocumentNumber) AS TotalNumberIncomingLetters
FROM IncomingLetter
WHERE Assigned_To_Department.Short_Name="My Department Name";
This does not work, whereas I found examples that are using this syntax. However, it is probably important to notice, that I m using this query in MS access.
You should use
The “My Department Name” text is actually stored in the
Departmentstable, and only the number (1) is stored in theIncomingLettertable, in the fieldAssigned_To_Department.Asking for
Assigned_To_Department.Short_Namebasically asks the number 1 to get it’sShort_Namefield, that does not make sense.You need to tell the database engine two things in these scenarios:
IncomingLetterandDepartmentsin this case (theinner joinpart)Assigned_To_DepartmentandIDfields respecively (theon ...part