Edit: Please see new information below, under Update.
I have an Access database with 4 tables: Table 1, 2, 3, and 4. Each table has 4 columns: ID, Date, Name, and Item.
I am trying to design a Query that will produce a count of a unique value within the Item column, grouped by the Date and Name. For example, when I run the Query, it should display the date, name of the individual, and a total count of how many times the word "Apple" occurs in the Item column for the applicable associate.
I am using Count Iif to count the occurrences and Union All to combine my tables. (Sample code below)
Problem: My Query is only providing a count from two of the tables, instead of all four. I am unable to determine why and need help trying to isolate the problem. I am now able to get the information to count the data from all four tables (by just recreating it from scratch, sigh). However, it's now providing me a total per table and I want it to provide a grand total from all 4 tables. For example: It's showing me a total of 1 apple for table 1, 2 apples for table 2, 3 apples for table 3 when I would like a Query/Report that just gives me the grand total of apples (6). I'm probably overlooking something here.
Update: I decided to create a brand new database with dummy information and manually retyped the code (to appease the old gods) and... it works. the issue is technically resolved at this point. I just now have to figure out why it's not giving me a 'total' number.
Here is an example of the SQL:
SELECT Table1.Date, Table1.Name, Count(IIf([Table1]![Item]="Apples",1,Null)) AS CountApples, Count(IIf([Table1]![Item]="Oranges",1,Null)) AS CountOranges, Count(IIf([Table1]![Item]="Pears",1,Null)) AS CountPears
FROM Table1
GROUP BY Table1.Date, Table1.Name
HAVING (((Table1.Date) Between [SS/SS/SS] And [EE/EE/EE]) AND ((Table1.Name) Like [Name]))
UNION ALL
SELECT Table2.Date, Table2.Name, Count(IIf([Table2]![Item]="Apples",1,Null)) AS CountApples, Count(IIf([Table2]![Item]="Oranges",1,Null)) AS CountOranges, Count(IIf([Table2]![Item]="Pears",1,Null)) AS CountPears
FROM Table2
GROUP BY Table2.Date, Table2.Name
HAVING (((Table2.Date) Between [SS/SS/SS] And [EE/EE/EE]) AND ((Table2.Name) Like [Name]))
UNION ALL
SELECT Table3.Date, Table3.Name, Count(IIf([Table3]![Item]="Apples",1,Null)) AS CountApples, Count(IIf([Table3]![Item]="Oranges",1,Null)) AS CountOranges, Count(IIf([Table3]![Item]="Pears",1,Null)) AS CountPears
FROM Table3
GROUP BY Table3.Date, Table3.Name
HAVING (((Table3.Date) Between [SS/SS/SS] And [EE/EE/EE]) AND ((Table3.Name) Like [Name]))
UNION ALL
SELECT Table4.Date, Table4.Name, Count(IIf([Table4]![Item]="Apples",1,Null)) AS CountApples, Count(IIf([Table4]![Item]="Oranges",1,Null)) AS CountOranges, Count(IIf([Table4]![Item]="Pears",1,Null)) AS CountPears
FROM Table4
GROUP BY Table4.Date, Table4.Name
HAVING (((Table4.Date) Between [SS/SS/SS] And [EE/EE/EE]) AND ((Table4.Name) Like [Name]));