Results 1 to 9 of 9
  1. #1
    polisasimo is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    9

    Two column join question

    Hello I am having a bit of trouble with a two column join query. The Customer table has 4 columns ID, NAME, STATE, PHONE_NUMBER. The Vendor table has 5 columns ID, NAME, STATE, PHONE_NUMBER, DISCOUNT.



    I built a query with a two column join on NAME and STATE that returns Customer.PHONE_NUMBER and Vendor.DISCOUNT. Some rows are being omitted from the return data set because some Vendor.STATE values are NULL.

    I need those returned in the query as well.

    Any information would be great.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Have you tried editing the join to return all records from the customer table (LEFT or RIGHT join)?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I don't understand joining Customer Name to Vendor Name.

    BTW, Name is a reserved word. Should avoid reserved words as field names.
    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.

  4. #4
    polisasimo is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    9
    I used fake column names for this post. I just need to figure out how to do a two column join wherein some of the values in one table are NULL. When I use the access join property options to create what would be an inner - outer. I get:

    The SQL statement could not be executed because it contains ambiguous outer joins. To force one of the joins to be performed first, create a separate query that performs the first join and then include that query in your SQL statement.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Both joins would need to be the same I suspect. Easier if you post the SQL.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    polisasimo is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    9
    SELECT [TableA].A, [TableA].B, TableB.A, TableB.B
    FROM [TableA] INNER JOIN TableB ON ([TableA].X= .TableB.X) AND ([TableA].[Y] = TableB.Y);

    Some records in TableA will have a NULL value in TableA.Y so I just need those records returned based on the TableA.X and TableB.X values being equal.

    Maybe I need a subquery?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Try changing INNER to RIGHT.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    polisasimo is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    9
    Changing INNER to RIGHT returns the TableB.A and TableB.B values but the records are missing the TableA.A and TableA.B data.

  9. #9
    polisasimo is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    9
    I think I figured it out thanks for pointing me in the right direction.

    SELECT [TableA].A, [TableA].B, TableB.A, TableB.B
    FROM [TableA] INNER JOIN TableB ON ([TableA].X= .TableB.X) AND (([TableA].[Y] = TableB.Y) OR (TableB.Y IS NULL));

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

Similar Threads

  1. Replies: 17
    Last Post: 08-27-2013, 10:21 PM
  2. Query table join question
    By Nelson8 in forum Queries
    Replies: 1
    Last Post: 07-26-2013, 08:08 AM
  3. Inner Join question.
    By Robeen in forum Queries
    Replies: 6
    Last Post: 09-21-2012, 03:08 PM
  4. Join Question
    By anunat in forum Access
    Replies: 1
    Last Post: 07-25-2012, 02:17 PM
  5. inner join question
    By silverxx12 in forum Queries
    Replies: 5
    Last Post: 02-15-2012, 11:56 AM

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