A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

how do I put these 2 queries into 1 ??



 
 
Thread Tools Display Modes
  #1  
Old February 5th, 2010, 09:04 PM posted to microsoft.public.access.queries
dannie
external usenet poster
 
Posts: 25
Default how do I put these 2 queries into 1 ??

What I would like is 1 query that displays the columns Area , CountofArea,
CountofArea2. I tried using the design query but it put a LEFT JOIN on the
whole first statement which gave me some crazy numbers. The first query is:

SELECT Area.Area, Count(InspectionsDI.Area) AS CountOfArea
FROM Area LEFT JOIN InspectionsDI ON Area.Area = InspectionsDI.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;

and then second query is:

SELECT Area.Area, Count(Inspections.Area) AS CountOfArea2
FROM Area LEFT JOIN Inspections ON Area.Area = Inspections.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;

thanks
  #2  
Old February 5th, 2010, 09:51 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default how do I put these 2 queries into 1 ??

Try this --
SELECT Area.Area, Count(InspectionsDI.Area) AS CountOfArea,
Count(Inspections.Area) AS CountOfArea2
FROM (Area LEFT JOIN InspectionsDI ON Area.Area = InspectionsDI.Area) LEFT
JOIN Inspections ON Area.Area = Inspections.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;


--
Build a little, test a little.


"dannie" wrote:

What I would like is 1 query that displays the columns Area , CountofArea,
CountofArea2. I tried using the design query but it put a LEFT JOIN on the
whole first statement which gave me some crazy numbers. The first query is:

SELECT Area.Area, Count(InspectionsDI.Area) AS CountOfArea
FROM Area LEFT JOIN InspectionsDI ON Area.Area = InspectionsDI.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;

and then second query is:

SELECT Area.Area, Count(Inspections.Area) AS CountOfArea2
FROM Area LEFT JOIN Inspections ON Area.Area = Inspections.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;

thanks

  #3  
Old February 5th, 2010, 10:41 PM posted to microsoft.public.access.queries
dannie
external usenet poster
 
Posts: 25
Default how do I put these 2 queries into 1 ??

When I try that it takes the value I get when the tables are separated and
multiplies them together and displays the quantity in both columns instead of
the individual counts.

"KARL DEWEY" wrote:

Try this --
SELECT Area.Area, Count(InspectionsDI.Area) AS CountOfArea,
Count(Inspections.Area) AS CountOfArea2
FROM (Area LEFT JOIN InspectionsDI ON Area.Area = InspectionsDI.Area) LEFT
JOIN Inspections ON Area.Area = Inspections.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;


--
Build a little, test a little.


"dannie" wrote:

What I would like is 1 query that displays the columns Area , CountofArea,
CountofArea2. I tried using the design query but it put a LEFT JOIN on the
whole first statement which gave me some crazy numbers. The first query is:

SELECT Area.Area, Count(InspectionsDI.Area) AS CountOfArea
FROM Area LEFT JOIN InspectionsDI ON Area.Area = InspectionsDI.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;

and then second query is:

SELECT Area.Area, Count(Inspections.Area) AS CountOfArea2
FROM Area LEFT JOIN Inspections ON Area.Area = Inspections.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;

thanks

  #4  
Old February 5th, 2010, 11:17 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default how do I put these 2 queries into 1 ??

UNTESTED but should work --
qryAreaCounts --
SELECT Area.Area, Count(InspectionsDI.Area) AS CountOfArea, 0 AS CountOfArea2
FROM Area LEFT JOIN InspectionsDI ON Area.Area = InspectionsDI.Area
GROUP BY Area.Area
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID
UNION ALL SELECT Area.Area, 0 AS CountOfArea, Count(Inspections.Area) AS
CountOfArea2
FROM Area LEFT JOIN Inspections ON Area.Area = Inspections.Area
GROUP BY Area.Area
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;

SELECT Area, Sum(CountOfArea) AS CountArea1,Sum(CountOfArea2) AS CountArea2
FROM qryAreaCounts
GROUP BY Area;

--
Build a little, test a little.


"dannie" wrote:

When I try that it takes the value I get when the tables are separated and
multiplies them together and displays the quantity in both columns instead of
the individual counts.

"KARL DEWEY" wrote:

Try this --
SELECT Area.Area, Count(InspectionsDI.Area) AS CountOfArea,
Count(Inspections.Area) AS CountOfArea2
FROM (Area LEFT JOIN InspectionsDI ON Area.Area = InspectionsDI.Area) LEFT
JOIN Inspections ON Area.Area = Inspections.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;


--
Build a little, test a little.


"dannie" wrote:

What I would like is 1 query that displays the columns Area , CountofArea,
CountofArea2. I tried using the design query but it put a LEFT JOIN on the
whole first statement which gave me some crazy numbers. The first query is:

SELECT Area.Area, Count(InspectionsDI.Area) AS CountOfArea
FROM Area LEFT JOIN InspectionsDI ON Area.Area = InspectionsDI.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;

and then second query is:

SELECT Area.Area, Count(Inspections.Area) AS CountOfArea2
FROM Area LEFT JOIN Inspections ON Area.Area = Inspections.Area
GROUP BY Area.Area, Area.ID
HAVING (((Area.Area)"" And (Area.Area)"ALL"))
ORDER BY Area.ID;

thanks

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:31 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.