J
Jeff
Hi
I'm doing a join of many queries into 1 query so that I can use all
this data in one report, and also to sum it up for another.
However, while I just want 1 record per neighborhood, I am getting
duplicate records of a few neighborhoods instead.
Could someone help explain why this is happening?
I've included the SQL to help.
Thanks
Jeff
SELECT [Van Clients query].[Van Neighborhood Served], [Van Clients
query].CountOfDemogID, [Van Clients query].SumFirstTime, [Van Client
Activity Count Query].SumofActiveClients, [Van Immunization
Query].ImmunCount, [Van Immunization Query].NonImmunCount, [Van
Immunization Query].UnknownImmunCount, [Van Delivered
Query].CountOfPregnancyID, [Van Delivered Query].TermNormalBirth, [Van
Delivered Query].PTLTermlBirth, [Van Delivered Query].PTLPTDBirth,
[Van Delivered Query].SumofPTL, [Van Delivered Query].SumofPTD, [Van
Delivered Query].SumofLBW, [Van Delivered Query].SumofVLBW, [Van
Delivered Query].SumofELBW, [Van Deceased Query].SumofMiscarry, [Van
Deceased Query].SumDeceased, [Van Deceased Query].SumLTF, [Van
Delivered Query].[SumOfNumber of Prenatal Visits - Kept], [SumOfNumber
of Prenatal Visits - Kept]/[CountOfPregnancyID] AS [Avg Prenatal
Kept], [Van FYOL Ed Query.CountOfFYOLID] AS CountOfFYOLIDBirth, [Van
FYOL6 Ed Query.CountOfFYOLID] AS CountOfFYOLID6mo, [Van Pregnancy
Query].PregnancyCount, [Van Pregnancy Query].PosCount, [Van Pregnancy
Query].NegCount, [Van Prenatal Ed Query].CountOfVanID, [Van FYOL6 Ed
Query].SSICountFYOL6mo, [Van FYOL Ed Query].SSICountFYOLBirth, [Van
Womenshealth Query].SSICountWH, [Van PN Total Query].PNClients, [Van
FYOL Total Query].FYOLClients, [Van Prenatal Ed Query].SSICountPrenat,
Nz([SSICountFYOL6mo])+Nz([SSICountFYOLBirth])+Nz([SSICountPrenat])
+Nz([SSICountWH]) AS TotalSSICount, [Van VVisit UnionAll Query].
[CountOfEducation Date], [Van VVisit Prenat Query].[CountOfEducation
Date], [Van Clients query].[HMB Report Start Date], [Van Clients
query].[HMB Report Stop Date]
FROM ((((((((((((([Van Clients query] LEFT JOIN [Van Immunization
Query] ON [Van Clients query].[Van Neighborhood Served] = [Van
Immunization Query].[Van Neighborhood Served]) LEFT JOIN [Van
Delivered Query] ON [Van Clients query].[Van Neighborhood Served] =
[Van Delivered Query].[Van Neighborhood Served]) LEFT JOIN [Van FYOL
Ed Query] ON [Van Clients query].[Van Neighborhood Served] = [Van FYOL
Ed Query].[Van Neighborhood Served]) LEFT JOIN [Van FYOL6 Ed Query] ON
[Van Clients query].[Van Neighborhood Served] = [Van FYOL6 Ed Query].
[Van Neighborhood Served]) LEFT JOIN [Van Immunization Query] AS [Van
Immunization Query_1] ON [Van Clients query].[Van Neighborhood Served]
= [Van Immunization Query_1].[Van Neighborhood Served]) LEFT JOIN [Van
Pregnancy Query] ON [Van Clients query].[Van Neighborhood Served] =
[Van Pregnancy Query].[Van Neighborhood Served]) LEFT JOIN [Van
Prenatal Ed Query] ON [Van Clients query].[Van Neighborhood Served] =
[Van Prenatal Ed Query].[Van Neighborhood Served]) LEFT JOIN [Van
Womenshealth Query] ON [Van Clients query].[Van Neighborhood Served] =
[Van Womenshealth Query].[Van Neighborhood Served]) LEFT JOIN [Van
VVisit UnionAll Query] ON [Van Clients query].[Van Neighborhood
Served] = [Van VVisit UnionAll Query].[Van Neighborhood Served]) LEFT
JOIN [Van VVisit Prenat Query] ON [Van Clients query].[Van
Neighborhood Served] = [Van VVisit Prenat Query].[Van Neighborhood
Served]) LEFT JOIN [Van Deceased Query] ON [Van Clients query].[Van
Neighborhood Served] = [Van Deceased Query].[Van Neighborhood Served])
LEFT JOIN [Van Client Activity Count Query] ON [Van Clients query].
[Van Neighborhood Served] = [Van Client Activity Count Query].[Van
Neighborhood Served]) LEFT JOIN [Van FYOL Total Query] ON [Van Clients
query].[Van Neighborhood Served] = [Van FYOL Total Query].[Van
Neighborhood Served]) LEFT JOIN [Van PN Total Query] ON [Van Clients
query].[Van Neighborhood Served] = [Van PN Total Query].[Van
Neighborhood Served]
WHERE ((([Van Clients query].[Van Neighborhood Served])<>"City
Heights" And ([Van Clients query].[Van Neighborhood Served])<>"Newport
- Brighton Center" And ([Van Clients query].[Van Neighborhood
Served])<>"Newport - Housing Authority"))
GROUP BY [Van Clients query].[Van Neighborhood Served], [Van Clients
query].CountOfDemogID, [Van Clients query].SumFirstTime, [Van Client
Activity Count Query].SumofActiveClients, [Van Immunization
Query].ImmunCount, [Van Immunization Query].NonImmunCount, [Van
Immunization Query].UnknownImmunCount, [Van Delivered
Query].CountOfPregnancyID, [Van Delivered Query].TermNormalBirth, [Van
Delivered Query].PTLTermlBirth, [Van Delivered Query].PTLPTDBirth,
[Van Delivered Query].SumofPTL, [Van Delivered Query].SumofPTD, [Van
Delivered Query].SumofLBW, [Van Delivered Query].SumofVLBW, [Van
Delivered Query].SumofELBW, [Van Deceased Query].SumofMiscarry, [Van
Deceased Query].SumDeceased, [Van Deceased Query].SumLTF, [Van
Delivered Query].[SumOfNumber of Prenatal Visits - Kept], [Van FYOL Ed
Query.CountOfFYOLID], [Van FYOL6 Ed Query.CountOfFYOLID], [Van
Pregnancy Query].PregnancyCount, [Van Pregnancy Query].PosCount, [Van
Pregnancy Query].NegCount, [Van Prenatal Ed Query].CountOfVanID, [Van
FYOL6 Ed Query].SSICountFYOL6mo, [Van FYOL Ed
Query].SSICountFYOLBirth, [Van Womenshealth Query].SSICountWH, [Van PN
Total Query].PNClients, [Van FYOL Total Query].FYOLClients, [Van
Prenatal Ed Query].SSICountPrenat, Nz([SSICountFYOL6mo])
+Nz([SSICountFYOLBirth])+Nz([SSICountPrenat])+Nz([SSICountWH]), [Van
VVisit UnionAll Query].[CountOfEducation Date], [Van VVisit Prenat
Query].[CountOfEducation Date], [Van Clients query].[HMB Report Start
Date], [Van Clients query].[HMB Report Stop Date];
I'm doing a join of many queries into 1 query so that I can use all
this data in one report, and also to sum it up for another.
However, while I just want 1 record per neighborhood, I am getting
duplicate records of a few neighborhoods instead.
Could someone help explain why this is happening?
I've included the SQL to help.
Thanks
Jeff
SELECT [Van Clients query].[Van Neighborhood Served], [Van Clients
query].CountOfDemogID, [Van Clients query].SumFirstTime, [Van Client
Activity Count Query].SumofActiveClients, [Van Immunization
Query].ImmunCount, [Van Immunization Query].NonImmunCount, [Van
Immunization Query].UnknownImmunCount, [Van Delivered
Query].CountOfPregnancyID, [Van Delivered Query].TermNormalBirth, [Van
Delivered Query].PTLTermlBirth, [Van Delivered Query].PTLPTDBirth,
[Van Delivered Query].SumofPTL, [Van Delivered Query].SumofPTD, [Van
Delivered Query].SumofLBW, [Van Delivered Query].SumofVLBW, [Van
Delivered Query].SumofELBW, [Van Deceased Query].SumofMiscarry, [Van
Deceased Query].SumDeceased, [Van Deceased Query].SumLTF, [Van
Delivered Query].[SumOfNumber of Prenatal Visits - Kept], [SumOfNumber
of Prenatal Visits - Kept]/[CountOfPregnancyID] AS [Avg Prenatal
Kept], [Van FYOL Ed Query.CountOfFYOLID] AS CountOfFYOLIDBirth, [Van
FYOL6 Ed Query.CountOfFYOLID] AS CountOfFYOLID6mo, [Van Pregnancy
Query].PregnancyCount, [Van Pregnancy Query].PosCount, [Van Pregnancy
Query].NegCount, [Van Prenatal Ed Query].CountOfVanID, [Van FYOL6 Ed
Query].SSICountFYOL6mo, [Van FYOL Ed Query].SSICountFYOLBirth, [Van
Womenshealth Query].SSICountWH, [Van PN Total Query].PNClients, [Van
FYOL Total Query].FYOLClients, [Van Prenatal Ed Query].SSICountPrenat,
Nz([SSICountFYOL6mo])+Nz([SSICountFYOLBirth])+Nz([SSICountPrenat])
+Nz([SSICountWH]) AS TotalSSICount, [Van VVisit UnionAll Query].
[CountOfEducation Date], [Van VVisit Prenat Query].[CountOfEducation
Date], [Van Clients query].[HMB Report Start Date], [Van Clients
query].[HMB Report Stop Date]
FROM ((((((((((((([Van Clients query] LEFT JOIN [Van Immunization
Query] ON [Van Clients query].[Van Neighborhood Served] = [Van
Immunization Query].[Van Neighborhood Served]) LEFT JOIN [Van
Delivered Query] ON [Van Clients query].[Van Neighborhood Served] =
[Van Delivered Query].[Van Neighborhood Served]) LEFT JOIN [Van FYOL
Ed Query] ON [Van Clients query].[Van Neighborhood Served] = [Van FYOL
Ed Query].[Van Neighborhood Served]) LEFT JOIN [Van FYOL6 Ed Query] ON
[Van Clients query].[Van Neighborhood Served] = [Van FYOL6 Ed Query].
[Van Neighborhood Served]) LEFT JOIN [Van Immunization Query] AS [Van
Immunization Query_1] ON [Van Clients query].[Van Neighborhood Served]
= [Van Immunization Query_1].[Van Neighborhood Served]) LEFT JOIN [Van
Pregnancy Query] ON [Van Clients query].[Van Neighborhood Served] =
[Van Pregnancy Query].[Van Neighborhood Served]) LEFT JOIN [Van
Prenatal Ed Query] ON [Van Clients query].[Van Neighborhood Served] =
[Van Prenatal Ed Query].[Van Neighborhood Served]) LEFT JOIN [Van
Womenshealth Query] ON [Van Clients query].[Van Neighborhood Served] =
[Van Womenshealth Query].[Van Neighborhood Served]) LEFT JOIN [Van
VVisit UnionAll Query] ON [Van Clients query].[Van Neighborhood
Served] = [Van VVisit UnionAll Query].[Van Neighborhood Served]) LEFT
JOIN [Van VVisit Prenat Query] ON [Van Clients query].[Van
Neighborhood Served] = [Van VVisit Prenat Query].[Van Neighborhood
Served]) LEFT JOIN [Van Deceased Query] ON [Van Clients query].[Van
Neighborhood Served] = [Van Deceased Query].[Van Neighborhood Served])
LEFT JOIN [Van Client Activity Count Query] ON [Van Clients query].
[Van Neighborhood Served] = [Van Client Activity Count Query].[Van
Neighborhood Served]) LEFT JOIN [Van FYOL Total Query] ON [Van Clients
query].[Van Neighborhood Served] = [Van FYOL Total Query].[Van
Neighborhood Served]) LEFT JOIN [Van PN Total Query] ON [Van Clients
query].[Van Neighborhood Served] = [Van PN Total Query].[Van
Neighborhood Served]
WHERE ((([Van Clients query].[Van Neighborhood Served])<>"City
Heights" And ([Van Clients query].[Van Neighborhood Served])<>"Newport
- Brighton Center" And ([Van Clients query].[Van Neighborhood
Served])<>"Newport - Housing Authority"))
GROUP BY [Van Clients query].[Van Neighborhood Served], [Van Clients
query].CountOfDemogID, [Van Clients query].SumFirstTime, [Van Client
Activity Count Query].SumofActiveClients, [Van Immunization
Query].ImmunCount, [Van Immunization Query].NonImmunCount, [Van
Immunization Query].UnknownImmunCount, [Van Delivered
Query].CountOfPregnancyID, [Van Delivered Query].TermNormalBirth, [Van
Delivered Query].PTLTermlBirth, [Van Delivered Query].PTLPTDBirth,
[Van Delivered Query].SumofPTL, [Van Delivered Query].SumofPTD, [Van
Delivered Query].SumofLBW, [Van Delivered Query].SumofVLBW, [Van
Delivered Query].SumofELBW, [Van Deceased Query].SumofMiscarry, [Van
Deceased Query].SumDeceased, [Van Deceased Query].SumLTF, [Van
Delivered Query].[SumOfNumber of Prenatal Visits - Kept], [Van FYOL Ed
Query.CountOfFYOLID], [Van FYOL6 Ed Query.CountOfFYOLID], [Van
Pregnancy Query].PregnancyCount, [Van Pregnancy Query].PosCount, [Van
Pregnancy Query].NegCount, [Van Prenatal Ed Query].CountOfVanID, [Van
FYOL6 Ed Query].SSICountFYOL6mo, [Van FYOL Ed
Query].SSICountFYOLBirth, [Van Womenshealth Query].SSICountWH, [Van PN
Total Query].PNClients, [Van FYOL Total Query].FYOLClients, [Van
Prenatal Ed Query].SSICountPrenat, Nz([SSICountFYOL6mo])
+Nz([SSICountFYOLBirth])+Nz([SSICountPrenat])+Nz([SSICountWH]), [Van
VVisit UnionAll Query].[CountOfEducation Date], [Van VVisit Prenat
Query].[CountOfEducation Date], [Van Clients query].[HMB Report Start
Date], [Van Clients query].[HMB Report Stop Date];