Combining 3 Queries that have a "count" in them

Maddison2_98

New member
Local time
Today, 10:57
Joined
Mar 22, 2004
Messages
5
I have the following queries with these fields (which the queries on their own work great):

qryEvent
CountOfEventNumber
EventDescription

qrySite
CountOfSiteNumber
SiteDescription

qryTopic
CountOfTopicNumber
TopicDescription

How can I link these in one query so that the counts only come across??, and has zero as a holder so all the items line up.

I hope this makes sense.

ie. for Event Number 261 Health(EventDescription) = 14 as a count (CountOfEvent); Site Number 44 Nutrition (SiteDescription) = 23 as a count (CountOfSite); Topic Number 10 Presentation to Staff (TopicDescription) = 56 as a count (CountofTopic)

I had someone start me off but it doesn't work at all. I want to bring the 3 into 1 so I don't have to have three seperate reports. :confused:
 
Last edited:
Have you tried UNION to make them as one?
 
Combining 3 Queries with "count" in them

This is what I've tried:

SELECT Count(Event.EventNumber) AS CountOfEventNumber, [All Tracking Information].EventNumber
FROM Event INNER JOIN [All Tracking Information] ON Event.EventNumber = [All Tracking Information].EventNumber
GROUP BY [All Tracking Information].EventNumber, Event.EventDescription

UNION ALL

SELECT Count(Site.SiteNumber) AS CountOfSiteNumber, Site.SiteNumber
FROM Site INNER JOIN [All Tracking Information] ON Site.SiteNumber = [All Tracking Information].SiteNumber
GROUP BY Site.SiteNumber, Site.SiteDescription

UNION ALL SELECT Count(Topic.TopicNumber) AS CountOfTopicNumber, Topic.TopicNumber
FROM Topic INNER JOIN [All Tracking Information] ON Topic.TopicNumber = [All Tracking Information].TopicNumber
GROUP BY Topic.TopicNumber, Topic.TopicDescription;

But it gives me:

CountOfEvent = all the numbers from the three queries (count of each below)
Event = all the numbers from the three queries (Event/Site/Topic numbers)

Now I need to make it so it has:
CountOfEvent, Event; CountOfSite, Site; CountOfTopic, Topic, so I end up with 6 columns not just the two, I need to seperate them somehow and not sure how to do it. A friend gave me this but then I'm not sure how to do the Topic Information.

SELECT [All Tracking Information].FirstName, Event.EventNumber as event, 0 as site, Count(Event.EventNumber) AS CountOfEventNumber
FROM Event INNER JOIN [All Tracking Information] ON Event.EventNumber = [All Tracking Information].EventNumber
GROUP BY [All Tracking Information].FirstName, Event.EventNumber;

UNION SELECT [All Tracking Information].FirstName, 0 as event, Site.SiteNumber as site, Count(Site.SiteNumber) AS CountOfSiteNumber
FROM Site INNER JOIN [All Tracking Information] ON Site.SiteNumber = [All Tracking Information].SiteNumber
GROUP BY [All Tracking Information].FirstName, Site.SiteNumber;

:confused: :confused:
 

Users who are viewing this thread

Back
Top Bottom