Results 1 to 7 of 7
  1. #1
    Les Isaacs is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Apr 2022
    Posts
    7

    Union query?

    Hi All

    I have a query [qryFees] which includes the date field [accsDate], currency fields [credit] and [debit] and text field [practice] (plus others).


    I have a table [tblFeesDue] which includes the date field [DueDate], currency field [fee], and text field [practice] (plus others).
    The two fields [practice] (in [qryFees] and [tblFeesDue]) are related - ie represent the same data
    I need a query that will output all the records from [qryFees] and all the records from [tblFeesDue], so that I can see, for each [practice], all the records from either table.
    Essentially, [qryFees] outputs all the payments actually made to/from each [practice], and [tblFeesDue] holds all the amounts periodically due from each [practice] (ie the standing payments they should have paid!), and I need to generate statements showing all payments along with all the standing payments (and resulting balances).

    I've been struggling with this for too long now, so hope someone can help?

    Many thanks
    Les

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    Make 1 query for each: qsFees, & qsFeesDue
    make sure they both have same fields in same order, then union is:

    select * from qsFees
    union
    select * from qsFeesDue

  3. #3
    Les Isaacs is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Apr 2022
    Posts
    7
    Hi ranman - thanks for your reply. I did try something like that, but a problem is that there are two currency fields [debit] and [credit] in [qryFees], but only one currency field [fee] is [tblFeesDue] - and the output needs to include all records with values in any of the 3 fields. So I'm not sure how to 'match' the one currency field with the two?

    Thanks again.
    Les

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    create a zero field, Fee:0

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,655
    you can use an alias as a placeholder

    Code:
    select credit, debit, 0 as fee from ...
    union
    select 0 as credit, 0 as debit, fees from ...
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,953
    First SELECT line dictates data type and field names.

    SELECT practice, credit, debit, 0 AS Fee FROM ...
    UNION
    SELECT practice, 0, 0, fee FROM ...

    Each SELECT line can be sql that JOINs tables or JOIN this UNION in another query to table.

    UNION will not allow duplicate rows. Use UNION ALL if need every record, even if there are duplicates.
    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.

  7. #7
    Les Isaacs is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Apr 2022
    Posts
    7
    Brilliant - placeholders - that's what I hadn't thought of!
    Many thanks guys

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

Similar Threads

  1. Replies: 3
    Last Post: 01-03-2020, 12:36 PM
  2. Replies: 3
    Last Post: 11-29-2018, 03:18 PM
  3. Replies: 4
    Last Post: 08-09-2017, 12:06 PM
  4. Convert Union Query to non-union help
    By Ekhart in forum Queries
    Replies: 2
    Last Post: 01-10-2017, 03:39 AM
  5. Replies: 4
    Last Post: 12-20-2015, 02:35 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