Results 1 to 3 of 3
  1. #1
    deluga.69 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    6

    Union Query Returning Different Data

    I have six select queries that pull the same Top 5 data for different distributors. They all work perfectly as individual queries but when I join them in a Union query i no longer get the the Top 5 returns.

    Any ideas? Here's the first union (there are four more):

    SELECT TOP 5 tbl_Distributor_Report_Names.dist_display_name, dbo_pictures.picture_name, Sum(dbo_grosses_master.gross_amount) AS release_amount
    FROM tbl_Date_Range, (((dbo_grosses_master INNER JOIN dbo_releases ON dbo_grosses_master.release_id = dbo_releases.release_id) INNER JOIN dbo_pictures ON dbo_releases.picture_id = dbo_pictures.picture_id) INNER JOIN dbo_labels ON dbo_pictures.label_id = dbo_labels.label_id) INNER JOIN tbl_Distributor_Report_Names ON dbo_labels.distributor_id = tbl_Distributor_Report_Names.distributor_id


    WHERE (((dbo_grosses_master.gross_start_date) Between [start_date] And [end_date]))
    GROUP BY tbl_Distributor_Report_Names.dist_display_name, dbo_pictures.picture_name, dbo_labels.distributor_id, dbo_grosses_master.release_id
    HAVING (((dbo_labels.distributor_id)=1))
    UNION ALL
    SELECT TOP 5 tbl_Distributor_Report_Names.dist_display_name, dbo_pictures.picture_name, Sum(dbo_grosses_master.gross_amount) AS release_amount
    FROM tbl_Date_Range, (((dbo_grosses_master INNER JOIN dbo_releases ON dbo_grosses_master.release_id = dbo_releases.release_id) INNER JOIN dbo_pictures ON dbo_releases.picture_id = dbo_pictures.picture_id) INNER JOIN dbo_labels ON dbo_pictures.label_id = dbo_labels.label_id) INNER JOIN tbl_Distributor_Report_Names ON dbo_labels.distributor_id = tbl_Distributor_Report_Names.distributor_id
    WHERE (((dbo_grosses_master.gross_start_date) Between [start_date] And [end_date]))
    GROUP BY tbl_Distributor_Report_Names.dist_display_name, dbo_pictures.picture_name, dbo_labels.distributor_id, dbo_grosses_master.release_id
    HAVING (((dbo_labels.distributor_id)=3))
    ORDER BY release_amount;

  2. #2
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209

    Union Query Returning Different Data

    Use the TOP 5 Queries themselves as Source for the UNION Query rather than copying it's SQL.

    If you look at the first SQL, in the example given above, the ORDER BY Clause is missing. So the TOP 5 clause of the first Query has no meaning.

  3. #3
    deluga.69 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    6
    Well, after the proverbial "duh" moment, I applied your suggestion and it worked perfectly.

    Thank you so much!

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

Similar Threads

  1. Queries not returning data
    By Verso in forum Queries
    Replies: 1
    Last Post: 08-11-2011, 01:46 AM
  2. Simple Query not returning any data.
    By psoli in forum Queries
    Replies: 4
    Last Post: 06-16-2011, 11:07 AM
  3. Please help me out with union query
    By radicrains in forum Access
    Replies: 1
    Last Post: 10-29-2010, 01:48 AM
  4. Union query only returning 255 characters
    By jpkeller55 in forum Queries
    Replies: 25
    Last Post: 10-05-2010, 05:51 AM
  5. Need help with a Union Query
    By jdowdy in forum Access
    Replies: 1
    Last Post: 10-13-2009, 05:24 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