Results 1 to 5 of 5
  1. #1
    newbieaccess203 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    21

    Join Query Help

    i have small simple table where some rows of column STR and NBR are exactly the same but have different MDR number.
    As to make my point clear I have divided that in different color group. For e.g. If you notice blue color has STR and NBR duplicated in both row but MDR is different. Same with yellow and green group.

    I am looking to create a command button(name it NEXT) in access forum/dashboard, which will be show me the result like blue color and than when I click that button(NEXT BUTTON), it should show me yellow records, when i click next it should show me green button.

    mainly how should i write query to display that result ?



    I tried this query:
    SELECT *
    FROM Table1 AS s1
    INNER JOIN Table1 AS s2
    ON
    (s2.STR = s1.STR OR
    s2.NBR = s1.NBR
    )
    WHERE
    s1.[MDR] <> s2.[MDR];

    But it does not give me the desired result I am looking for.
    Attached Files Attached Files

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I cannot download your image from my current location, and I cannot say that I totally understand your question, but I think I see one potential issue:
    Code:
    INNER JOIN Table1 AS s2 
    ON 
    (s2.STR = s1.STR OR
    s2.NBR = s1.NBR
    )
    I have never seen OR used in a JOIN clause. I don't think that is is possible. You may need to move that down to your WHERE clause.

    Note that while it is rare, it is valid to have a query between two tables with no JOIN statement. That would create a Cartesian Product between your two tables, but your WHERE clause should limit it to just the records that you want to return.

  3. #3
    newbieaccess203 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    21

    Again added the tables

    so again added tables in both pdf and zip format and under zip it is xls file so hopefully you should be able to open the table and see what I am talking about.

    I want to build the query where it will display first display records in purple color and clicking next button on form should display yellow color records and than green color.

    Please understand i colored the records to explain what type of output i am looking for the query.
    The reason i color first two records purple because it has STR and NBR are same in both the rows and MDR number is different.

    Same with other colored records.

    HOPEFULLY I AM ABLE TO EXPLAIN CLEARLY WHAT TYPE OF OUTPUT I AM EXPECTING FROM QUERY.

    I TRIED TO CREATE QUERY BY MYSELF:
    SELECT T1.Region, T1.STR, T1.NBR, T1.DESCR, T1.MDR
    FROM Table1 AS T1
    INNER JOIN Table1 AS T2
    ON T1.STR = T2.STR AND T1.NBR = T2.NBR
    WHERE T1.MDR<>T2.MDR
    ORDER BY T1.STR, T1.NBR;

    BUT IT DISPLAY THE POP TEXT BOX FOR ASKING ME TO ENTER THE VALUE

    I JUST WANT TO DISPLAY THE RECORDS
    Attached Files Attached Files

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I think it would be much more beneficial if you could post a sample database (not just screen prints of your desired output), so we can see what your data tables actually look like, why your query is behaving as it does.

  5. #5
    newbieaccess203 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    21

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. Help with a join query
    By abordeau in forum Queries
    Replies: 7
    Last Post: 10-03-2013, 11:51 AM
  3. Inner join query not quite right
    By coach32 in forum Queries
    Replies: 6
    Last Post: 07-07-2012, 03:13 AM
  4. Join Query
    By hithere in forum Queries
    Replies: 4
    Last Post: 02-17-2012, 06:18 AM
  5. inner join in query
    By Hrcko in forum Access
    Replies: 1
    Last Post: 02-01-2010, 05:54 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