Results 1 to 3 of 3
  1. #1
    Billabong is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2016
    Posts
    3

    Returning null records from double join

    I have a query using multiple tables, effectively and order header, order detail and then several supporting tables. One of these is a text table with a field I need but only if it’s record type 1.



    The join to the text table is based on two fields order_number and line_number and I need to return all records from order_header and order_detail and then insert null values into this data where there's no order_text of record type 1.

    At the minute my query only returns data where the order_text record_type is 1 so omits a lot of data. Can anyone help me with the syntax for the correct join for this please?

    SELECT DISTINCT ORDER.HEADER.ORDER_NUMBER, ORDER.DETAIL.LINE_NUMBER
    FROM LIORDER_AUF_TEXT INNER JOIN (ORDER.HEADER INNER JOIN ORDER_DETAIL ON ORDER.HEADER.ORDER_NUMBER = ORDER_DETAIL.ORDER_NUMBER) ON (ORDER_TEXT.LINE_NUMBER = ORDER.DETAIL.LINE_NUMBER) AND (ORDER _TEXT.ORDER_NUMBER = ORDER_DETAIL.ORDER_NUMBER)
    GROUP BY ORDER.HEADER.ORDER_NUMBER, ORDER.DETAIL.LINE_NUMBER, ORDER_TEXT.RECORD_TYPE, ORDER_TEXT.TEXT_DETAIL
    HAVING (((ORDER_TEXT.RECORD_TYPE)=1))
    ORDER BY ORDER.HEADER.ORDER_NUMBER, ORDER.DETAIL.LINE_NUMBER;


    TIA.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I probably won't be able to help you. Some of the tables names I see in the SQL are not valid.
    Access will not let you create a table name like ORDER.HEADER.
    Code:
    SELECT DISTINCT 
        ORDER.HEADER.ORDER_NUMBER, ORDER.DETAIL.LINE_NUMBER
    
    FROM 
        LIORDER_AUF_TEXT 
           INNER JOIN (
              ORDER.HEADER INNER JOIN ORDER_DETAIL 
           ON 
              ORDER.HEADER.ORDER_NUMBER = ORDER_DETAIL.ORDER_NUMBER) 
           ON (
              ORDER_TEXT.LINE_NUMBER = ORDER.DETAIL.LINE_NUMBER) AND (ORDER_TEXT.ORDER_NUMBER = ORDER_DETAIL.ORDER_NUMBER)
    
    GROUP BY 
        ORDER.HEADER.ORDER_NUMBER, ORDER.DETAIL.LINE_NUMBER, ORDER_TEXT.RECORD_TYPE, ORDER_TEXT.TEXT_DETAIL
    
    HAVING 
        (((ORDER_TEXT.RECORD_TYPE)=1))
    
    ORDER BY 
        ORDER.HEADER.ORDER_NUMBER, ORDER.DETAIL.LINE_NUMBER;

    Sometimes the table name changes: "ORDER.DETAIL" vs "ORDER_DETAIL"


    Not sure what you want to do.
    First you say
    One of these is a text table with a field I need but only if it’s record type 1
    Then you say
    return all records from order_header and order_detail and then insert null values into this data where there's no order_text of record type 1.

  3. #3
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    your wrote: "..my query only returns data where the order_text record_type is 1..."
    that would be consistent with the clause: HAVING (((ORDER_TEXT.RECORD_TYPE)=1))

    in general one cannot both select and insert as part of a single query; so I believe fundamentally you must make a query that selects the correct record set - save it with a name i.e. Q1 ....and then create an update or append query that begins with Q1 as part of its design sources

    If you seek the SQL syntax; then create the query using the visual design view so that it runs correctly - and then select the 'SQL VIew' option in order to see the syntax

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

Similar Threads

  1. Replies: 1
    Last Post: 04-15-2015, 10:52 AM
  2. Replies: 3
    Last Post: 03-05-2015, 02:28 PM
  3. Outer join not returning null values.
    By Count Duckula in forum Queries
    Replies: 3
    Last Post: 08-15-2013, 10:03 AM
  4. Replies: 1
    Last Post: 09-20-2011, 03:23 PM
  5. Returning correct rows in a join/nested query
    By goneaccessing in forum Queries
    Replies: 5
    Last Post: 03-03-2010, 12:21 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