Results 1 to 1 of 1
  1. #1
    marcchehab is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    1

    Query one field of one table in either of two fields of another table.


    Dear Accessers.
    This is my first post, I didn't find a solution to a problem I had online, but now figured it out myself. I thought I'd just post the solution, so that it's available. Maybe I didn't know the right words to find this too and the solution is obvious to everybody but me. Anyway, here it is.

    The problem is the following: If you have ONE field (e.g. PERSONID) in one table that can occur in TWO fields of another table, and you want to query all hits, where PERSONID occurs in EITHER of the two fields in the other table, you cannot use a straight forward join, because Access links multiple joins between two tables with logical AND operators.

    The obvious solution is: Use criteria instead of joins. However, I have a lot of data and it made my database VERY slow. In my query, joins are, literally, 100x faster.

    So, how I did it is:

    * Go to the SQL view
    * Locate the Join (mine looks like this):
    Code:
    FROM COWAlliancesPerYear INNER JOIN COWCountryCode ON (COWAlliancesPerYear.ccode2 = COWCountryCode.CCode) AND (COWAlliancesPerYear.ccode1 = COWCountryCode.CCode);
    * Change the AND to an OR:
    Code:
    FROM COWAlliancesPerYear INNER JOIN COWCountryCode ON (COWAlliancesPerYear.ccode2 = COWCountryCode.CCode) OR (COWAlliancesPerYear.ccode1 = COWCountryCode.CCode);
    and enjoy.

    Make sure you never go back to design view, it destroys the SQL apparently. Anybody knows how to prevent that?

    kind regards, hope it helps somebody.
    Last edited by marcchehab; 08-20-2013 at 07:46 AM. Reason: solved

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

Similar Threads

  1. Replies: 1
    Last Post: 06-11-2012, 02:34 PM
  2. Replies: 5
    Last Post: 03-01-2012, 12:59 AM
  3. Replies: 3
    Last Post: 02-24-2012, 06:20 PM
  4. Replies: 11
    Last Post: 09-15-2011, 03:52 PM
  5. Replies: 3
    Last Post: 08-16-2011, 02:20 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