View Full Version : Union Query


mrabrams
03-22-2002, 06:18 AM
I know I am reall close.
Query1 has 2 fields. RepName and RepReceived.
Query2 has 2 fields. RepName and RepVerified
Query3 has 2 fields. RepName and RepCompleted.

4th query I want RepName and all 3 counts.
The code I have enclosed works only if the Rep has a RepReceived. If he only has Verified or Completed, his name doesn't show.
I need ALL reps regardless if they have any or all 3 categories.
The NZ s working OK. I believe I need an additional join, but can't see it.

Any takers?

Much appreciated.
Thank you,

Michael Abrams

SELECT REPReceived.[REP NAME], REPReceived.[CountOfRecord #], REPVerified.[CountOfRecord #], REPCompleted.[CountOfRecord #], NZ([REPReceived].[COUNTOFRECORD #],0)+NZ([REPVERIFIED].[COUNTOFRECORD #],0)+NZ([REPCOMPLETED].[COUNTOFRECORD #],0) AS TOTAL
FROM (REPReceived LEFT JOIN REPVerified ON REPReceived.[REP NAME] = REPVerified.[REP NAME]) LEFT JOIN REPCompleted ON REPVerified.[REP NAME] = REPCompleted.[REP NAME];

Harry
03-22-2002, 06:39 AM
Create another query which only shows ALL reps (or alternatively use the field direct from the source table). Now use this as the source for the repname and NZ the corresponding values from the other queries.

HTH

mrabrams
03-22-2002, 07:01 AM
Thank you Harry.
Of course it works perfectly.

Have a good week end !!

Michael