Results 1 to 4 of 4
  1. #1
    Rramjet is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    36

    How to get a union query to return a single row per case?

    I have a union query

    SELECT CLIENT.ID, CLIENT.[First Name], CLIENT.[Last Name], CLIENT.[Team], CLIENT.[Referral date], CLIENT.[Closed date]," " as SDQ_Tot, " " as SDQ_P, " " as SDQ_C, " " as SDQ_O, " " as SDQ_T, " " as SDQ_S
    FROM CLIENT
    UNION
    SELECT CROSSTAB_SDQ.ID, " ", " ", " ", " ", " ", CROSSTAB_SDQ.[Total], CROSSTAB_SDQ.P, CROSSTAB_SDQ.C, CROSSTAB_SDQ.O, CROSSTAB_SDQ.T, CROSSTAB_SDQ.S


    FROM CROSSTAB_SDQ;

    that returns

    ID F name L Name Team Date 1 Date 2 Tot P C O T S
    1 3 1 2
    1 Bill Duck X 1/1/1900 2/2/2000
    2 5 1 3 1
    2 Bob Weave Y 1/1/1900 2/2/2000

    However, I need

    ID F name L Name Team Date 1 Date 2 Tot P C O T S
    1 Bill Duck X 1/1/1900 2/2/2000 3 1 2
    2 Bob Weave Y 1/1/1900 2/2/2000 5 1 3 1

    Is that possible to achieve?

    Then I want to add more unions to that query (there are a number of other counts and totals I need to bring in).

    Thanks,
    Rramjet.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Looks like to me should JOIN Client to Crosstab_SDQ instead of UNION.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Rramjet is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    36
    Okay - but if I simply replace "UNION" with "JOIN" that does not work. I am going to have to go and do some study as I have no idea how a "JOIN" SQL might be consrtucted (Unless you can quickly rewrite my UNION to conform to JOIN SQL syntax...

  4. #4
    Rramjet is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    36
    Okay - Yeah, right - I got it. Between the tables in a SELECT query (in Query Design) you can define the type of join by double clicking on the relationship line and specifying what you want displayed. In my case I need an "OUTER JOIN" to display all records from CLIENT and only those from the crosstab qeries where the "joined fields are equal". And no SQL coding necessary... (you can view it of course, but I don't need to in this case).

    Thanks heaps June 7!

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

Similar Threads

  1. Replies: 5
    Last Post: 10-23-2012, 03:55 PM
  2. Replies: 2
    Last Post: 07-27-2012, 08:27 AM
  3. Union Query to return Null
    By dr4ke in forum Queries
    Replies: 8
    Last Post: 07-06-2012, 12:18 AM
  4. return max/min value in single query
    By garamon in forum Access
    Replies: 2
    Last Post: 10-23-2011, 03:50 PM
  5. Exporting single query and single report.
    By rfhall50 in forum Programming
    Replies: 2
    Last Post: 02-18-2011, 12:08 PM

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