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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
Union Query Issue
Try 'Union All'. union is only matching records
|
Thread Tools | |
Display Modes | |
|
|
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 |