Results 1 to 7 of 7
  1. #1
    ynotaz is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    9

    Help with SQL join results


    This should be simple but I'm at a loss. Here are 2 SQL views of 2 queries. The first is for testing/verification the second is what I'm trying to get working. I've added the "where invno=14168" to segregate the results down to the one failing item. The first query returns 2 rows which is correct.

    SELECT InvLine.ID, InvLine.InvNo, InvLine.LineNo, InvLine.ItemDesc, InvLine.ItemSize, InvLine.Item, InvLine.Qty, InvLine.UnitPrice, InvLine.UOM, InvLine.ExtPrice, InvLine.ACCTClas
    FROM InvLine
    WHERE (((InvLine.InvNo)=14168));


    The second which matches back to the Item file to insure the current value of "ACCTclas" is retrieved returns 3 rows, one of which is a duplicate.

    SELECT InvLine.ID, InvLine.InvNo, InvLine.LineNo, InvLine.ItemDesc, InvLine.ItemSize, InvLine.Item, InvLine.Qty, InvLine.UnitPrice, InvLine.UOM, InvLine.ExtPrice, Item.ACCTClas
    FROM InvLine LEFT JOIN Item ON InvLine.Item = Item.ITEM
    WHERE (((InvLine.InvNo)=14168))
    ORDER BY InvLine.InvNo DESC;

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not much to go on, but maybe:

    Do the duplicate records EXACTLY match?
    Every field in both records are identical?
    Try
    Code:
    SELECT Distinct InvLine.ID, InvLine.InvNo, InvLine.LineNo, InvLine.ItemDesc, InvLine.ItemSize, InvLine.Item, InvLine.Qty, InvLine.UnitPrice, InvLine.UOM, InvLine.ExtPrice, Item.ACCTClas
    FROM InvLine LEFT JOIN Item ON InvLine.Item = Item.ITEM
    WHERE (((InvLine.InvNo)=14168))
    ORDER BY InvLine.InvNo DESC;

  3. #3
    ynotaz is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    9
    Thanks for the reply.

    Yes they do match exactly.

    The "ID" field is an autonumber field from the invline table : Here is a cut and paste of the 3 record output from the production query that incorporates item file to get the current AcctClass and then a test query selecting the same invoice line items without the join to the item table. The problem is the duplication of ID 15446 in the production query.


    ID InvNo LineNo ItemDesc ItemSize Item Qty UnitPrice UOM ExtPrice ACCTClas
    15447 14168 0 Overpayments and Donations Overpayments and Donations 9905 20 $1.00 EA $20.00 F
    15446 14168 0 Round Tubing 0.120 wall 1 1/2 2218 7 $1.78 FT $12.46 M
    15446 14168 0 Round Tubing 0.120 wall 1 1/2 2218 7 $1.78 FT $12.46 M

    ID InvNo LineNo ItemDesc ItemSize Item Qty UnitPrice UOM ExtPrice ACCTClas
    15446 14168 0 Round Tubing 0.120 wall 1 1/2 2218 7 $1.78 FT $12.46 M
    15447 14168 0 Overpayments and Donations Overpayments and Donations 9905 20 $1.00 EA $20.00 F

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Are you sure there aren't two records in Item table with ITEM number 2218? Suggest you double check by doing a filter on that value in Item table just to make sure.
    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.

  5. #5
    ynotaz is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    9
    Well wouldn't you know it. I was assured that the item table was correct and had just been checked. Well seems not so much.

    Thanks... I was pulling my hair out on this.....

    SOLVED

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Might want to set ITEM field at least as Index Yes (no duplicates) even if it isn't the primary key.
    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
    ynotaz is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    9
    Good idea. That will save future headaches.

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

Similar Threads

  1. Replies: 6
    Last Post: 11-19-2013, 01:38 AM
  2. Replies: 3
    Last Post: 05-01-2013, 09:52 AM
  3. Inner Join works but not Left Join
    By kwooten in forum Queries
    Replies: 1
    Last Post: 12-11-2012, 05:09 PM
  4. Replies: 6
    Last Post: 05-14-2012, 07:24 AM
  5. Outer Join Nested in Inner Join
    By Stevens7 in forum Queries
    Replies: 2
    Last Post: 10-19-2011, 01:34 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