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  

Union Query Issue



 
 
Thread Tools Display Modes
  #1  
Old July 10th, 2004, 03:05 PM
Larry
external usenet poster
 
Posts: n/a
Default Union Query Issue

Hi guys.

I'm using Access 97 (SP2) to do some work for a client.

I am running a Union Query on two tables tht are identical, to create one
set of data. Here is the syntax of the query:

SELECT Drills.Date, [Drills Subtable].MemberId
FROM Drills LEFT JOIN [Drills Subtable] ON Drills.DrillID = [Drills
Subtable].DrillID
WHERE (((Drills.Date) Between [Forms]![SummaryReport]![startdate] And
[Forms]![SummaryReport]![enddate]));

UNION SELECT [a Drills].Date, [a Drills Subtable].MemberId
FROM [A Drills] LEFT JOIN [a Drills Subtable] ON [a Drills].DrillID = [a
Drills Subtable].DrillID
WHERE ((([a Drills].Date) Between [Forms]![SummaryReport]![startdate] And
[Forms]![SummaryReport]![enddate]));

---------------------------------------
The table called Drills is the current table. The table called [a drills]
is an archive table.

There are currently records in the drills table, but no records in the
archive table.

If I run the query by ommitting the union statements, a particular member
will list 9 records (I verified in the tables that this was correct). If I
run the full query listed above, that same member lists only 5 records.
Does anyone have an idea what may be causing this?

Thanks,

Larry


  #2  
Old July 10th, 2004, 03:53 PM
Douglas J. Steele
external usenet poster
 
Posts: n/a
Default Union Query Issue

Are there duplicates? UNION eliminates duplicates.

To avoid having duplicates eliminated, use UNION ALL instead.

BTW, Date is not a good name for a field. It's a reserved word, and can lead
to problems.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Larry" wrote in message
...
Hi guys.

I'm using Access 97 (SP2) to do some work for a client.

I am running a Union Query on two tables tht are identical, to create one
set of data. Here is the syntax of the query:

SELECT Drills.Date, [Drills Subtable].MemberId
FROM Drills LEFT JOIN [Drills Subtable] ON Drills.DrillID = [Drills
Subtable].DrillID
WHERE (((Drills.Date) Between [Forms]![SummaryReport]![startdate] And
[Forms]![SummaryReport]![enddate]));

UNION SELECT [a Drills].Date, [a Drills Subtable].MemberId
FROM [A Drills] LEFT JOIN [a Drills Subtable] ON [a Drills].DrillID = [a
Drills Subtable].DrillID
WHERE ((([a Drills].Date) Between [Forms]![SummaryReport]![startdate] And
[Forms]![SummaryReport]![enddate]));

---------------------------------------
The table called Drills is the current table. The table called [a drills]
is an archive table.

There are currently records in the drills table, but no records in the
archive table.

If I run the query by ommitting the union statements, a particular member
will list 9 records (I verified in the tables that this was correct). If

I
run the full query listed above, that same member lists only 5 records.
Does anyone have an idea what may be causing this?

Thanks,

Larry




  #3  
Old July 10th, 2004, 04:49 PM
Larry
external usenet poster
 
Posts: n/a
Default Union Query Issue

Doug,

Adding the ALL statement fixed the problem. Turns out that ome of the
members had attended multiple drills on the same day, and since I was only
capturing memberid and date to do the count, the union query was eliminating
the duplicates.

Thanks for the help,

Larry

"Douglas J. Steele" wrote in message
...
Are there duplicates? UNION eliminates duplicates.

To avoid having duplicates eliminated, use UNION ALL instead.

BTW, Date is not a good name for a field. It's a reserved word, and can

lead
to problems.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Larry" wrote in message
...
Hi guys.

I'm using Access 97 (SP2) to do some work for a client.

I am running a Union Query on two tables tht are identical, to create

one
set of data. Here is the syntax of the query:

SELECT Drills.Date, [Drills Subtable].MemberId
FROM Drills LEFT JOIN [Drills Subtable] ON Drills.DrillID = [Drills
Subtable].DrillID
WHERE (((Drills.Date) Between [Forms]![SummaryReport]![startdate] And
[Forms]![SummaryReport]![enddate]));

UNION SELECT [a Drills].Date, [a Drills Subtable].MemberId
FROM [A Drills] LEFT JOIN [a Drills Subtable] ON [a Drills].DrillID = [a
Drills Subtable].DrillID
WHERE ((([a Drills].Date) Between [Forms]![SummaryReport]![startdate]

And
[Forms]![SummaryReport]![enddate]));

---------------------------------------
The table called Drills is the current table. The table called [a

drills]
is an archive table.

There are currently records in the drills table, but no records in the
archive table.

If I run the query by ommitting the union statements, a particular

member
will list 9 records (I verified in the tables that this was correct).

If
I
run the full query listed above, that same member lists only 5 records.
Does anyone have an idea what may be causing this?

Thanks,

Larry






  #4  
Old July 10th, 2004, 06:27 PM
Gary Walter
external usenet poster
 
Posts: n/a
Default Union Query Issue

Hi Larry,

I wonder if you shouldn't use

UNION ALL

instead of

UNION

"Larry" wrote:

I'm using Access 97 (SP2) to do some work for a client.

I am running a Union Query on two tables tht are identical, to create one
set of data. Here is the syntax of the query:

SELECT Drills.Date, [Drills Subtable].MemberId
FROM Drills LEFT JOIN [Drills Subtable] ON Drills.DrillID = [Drills
Subtable].DrillID
WHERE (((Drills.Date) Between [Forms]![SummaryReport]![startdate] And
[Forms]![SummaryReport]![enddate]));

UNION SELECT [a Drills].Date, [a Drills Subtable].MemberId
FROM [A Drills] LEFT JOIN [a Drills Subtable] ON [a Drills].DrillID = [a
Drills Subtable].DrillID
WHERE ((([a Drills].Date) Between [Forms]![SummaryReport]![startdate] And
[Forms]![SummaryReport]![enddate]));

---------------------------------------
The table called Drills is the current table. The table called [a drills]
is an archive table.

There are currently records in the drills table, but no records in the
archive table.

If I run the query by ommitting the union statements, a particular member
will list 9 records (I verified in the tables that this was correct). If I
run the full query listed above, that same member lists only 5 records.
Does anyone have an idea what may be causing this?

Thanks,

Larry




  #5  
Old July 12th, 2004, 08:53 AM
Pete S
external usenet poster
 
Posts: n/a
Default Union Query Issue

Try 'Union All'. union is only matching records
 




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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hidden files in Ms-Query cause ODBC connect errors or Query is wac needyourhelp General Discussion 4 July 12th, 2004 09:38 PM
UNION Query truncating Memo fields Matthew DeAngelis Running & Setting Up Queries 4 June 10th, 2004 02:17 PM
Edit table using union query De'Ville Running & Setting Up Queries 1 June 1st, 2004 11:46 AM
Union Query Not Working Properly JohnAFT Running & Setting Up Queries 1 May 24th, 2004 03:27 AM


All times are GMT +1. The time now is 05:30 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.