Results 1 to 6 of 6
  1. #1
    racefan91 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Sep 2013
    Posts
    57

    Union query to join two crosstab queries

    I have a table that has columns for two teams that play each other, a column for the winner, and a column for the loser. I then made two cross tab queries calculate winners and losers. I joined these two cross tab queries using a union query but there is no way to tell which rows came from which cross tab query. Is there some way to accomplish this? Attached are pictures for my table, the two cross tab queries and the union query.


    Click image for larger version. 

Name:	Table Matchups.jpg 
Views:	14 
Size:	132.6 KB 
ID:	13888Click image for larger version. 

Name:	Wins by Round Crosstab.jpg 
Views:	13 
Size:	86.5 KB 
ID:	13889Click image for larger version. 

Name:	Losses by Round Crosstab.jpg 
Views:	13 
Size:	87.6 KB 
ID:	13890Click image for larger version. 

Name:	Wins & Losses Crosstab Union.png 
Views:	13 
Size:	94.4 KB 
ID:	13891

    This is the sql for the union query
    SELECT *
    FROM [Qry_Matchups_Losses by Round-Crosstab]
    UNION SELECT [Qry_Matchups_Wins by Round-Crosstab].*
    FROM [Qry_Matchups_Wins by Round-Crosstab];

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    How about something like this?
    Code:
    SELECT [Qry_Matchups_Losses by Round-Crosstab].*,"Losses" as Query_Source
    FROM [Qry_Matchups_Losses by Round-Crosstab]
    UNION 
    SELECT [Qry_Matchups_Wins by Round-Crosstab].*,"Wins" as Query_Source
    FROM [Qry_Matchups_Wins by Round-Crosstab];

  3. #3
    racefan91 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Sep 2013
    Posts
    57
    I get an error saying "The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

  4. #4
    racefan91 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Sep 2013
    Posts
    57
    Figured it out by removing the comma after Query Source

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Oops, sorry about that typo. I have gone back and corrected it.

  6. #6
    racefan91 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Sep 2013
    Posts
    57
    Thanks a ton for the help!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 08-27-2013, 10:21 PM
  2. Union query- 9 Queries
    By JessieBee in forum Queries
    Replies: 3
    Last Post: 07-14-2012, 05:46 AM
  3. Union Query of 2 Crosstab
    By shawnjerome in forum Queries
    Replies: 1
    Last Post: 04-05-2012, 01:05 PM
  4. One filter for 3 Queries in Union Query
    By rlsublime in forum Access
    Replies: 3
    Last Post: 03-20-2012, 04:01 PM
  5. Union query (or Inner/Outer join?)
    By LilMissAttack in forum Queries
    Replies: 4
    Last Post: 10-23-2010, 12:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums