Results 1 to 11 of 11
  1. #1
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97

    A form that shows all possible combinations from a relationship join

    EDIT: SOLUTION: A Cartesian join will give you all possible combinations, which you get by NOT joining two tables in a query, but rather just pulling the fields in directly. I was trying so hard to use joins that it didn't occur to me NOT to use them.

    Greetings! I've somehow landed a job doing MS Access design, and I'm learning as I go. I'm building my first real relational database, and here's my situation.



    Edit for clarity

    Click image for larger version. 

Name:	Capture.PNG 
Views:	9 
Size:	6.4 KB 
ID:	32400

    Table One has three programs. Table Two has four titles. Thus there should be twelve possible combinations. I want a query that will show both full and empty combinations. I currently have three data points in Table three.

    I have tried the error message advice about making the first step a query and then using that as part of a second query, but it gives just the first query results with no additional lines.

    Any help would be much appreciated.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,929
    Sounds like you need to use left joins

    In the query designer, join your main data table to each of the other three tables. For each join, right click and select the second option - include all records from maintable and only those...... Include all columns from all tables at this stage, you can refine it later

    run your query. You will now see blanks in the other table columns where there is no matching data to maintable.

    if you only want to see records where there is missing data in one or more table, it is easier to set a criteria rather than trying to filter the query

    criteria would be something like

    ProgramID is Null or ContactsID is Null or TitlesID is null

  3. #3
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    I"m getting an error about ambiguous outer joins. I'll keep digging into it. I understand the theory, but the flaw is somewhere in my implementation. I'm going to create a test database just for this task instead of working in my active database, and try again.

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Something like this will create the ambiguous joins error

    Click image for larger version. 

Name:	AmbiguousJoins.PNG 
Views:	10 
Size:	27.4 KB 
ID:	32397

    To fix, ensure the join direction is consistent as below

    Click image for larger version. 

Name:	LeftJoins.PNG 
Views:	9 
Size:	12.9 KB 
ID:	32398
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    I think I understand the above. My issue is that I need them to go to the middle, as going in one direction wouldn't get the exponential results I want.

    Table 1 has 4 programs
    Table 2 has 3 titles
    Table 3 is where they link up, and has three data points.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	9 
Size:	6.4 KB 
ID:	32399

    However there are twelve possible combinations (4x3) and I want a form that will show all 12 of those combinations. I've tried doing what the error message says and making the first join a query and then using that in the second query, and that only give three results instead of the 12 I'm expecting.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,929
    Your joins are goint the wrong way, they should be from maindata, not to maindata.

    And if you want every possible combination then use what is called a Cartesian query - no joins at all

  7. #7
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by Ajax View Post
    Your joins are goint the wrong way, they should be from maindata, not to maindata.

    And if you want every possible combination then use what is called a Cartesian query - no joins at all
    Sounds Exotic. I'll look into that, thank you!

    EDIT; I GET IT NOW, THANK YOU! I was trying so hard to use joins that it didn't occur to me NOT to use them!
    Last edited by securitywyrm; 01-26-2018 at 12:56 PM. Reason: Thank you!

  8. #8
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Whilst Cartesian joins (AKA no joins) can at times be useful they should only be used in very limited situations
    Otherwise you will get lots of superfluous results if misused

    Just to clarify if the programs are called A,B,C and the titles are 1,2,3,4 you are saying you could have A1,A2,A3,A4,B1,B2,B3,B4,C1,C2,C3,C4 ?
    Perhaps you should review your table structure.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #9
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by ridders52 View Post
    Whilst Cartesian joins (AKA no joins) can at times be useful they should only be used in very limited situations
    Otherwise you will get lots of superfluous results if misused

    Just to clarify if the programs are called A,B,C and the titles are 1,2,3,4 you are saying you could have A1,A2,A3,A4,B1,B2,B3,B4,C1,C2,C3,C4 ?
    Perhaps you should review your table structure.
    It's for a contacts database. The old structure was one giant flat file. Unfortunately stuff keeps getting changed, which would break queries constantly, so now I'm making one where every field that could be changed can be changed without breaking anything.

    Right now my difficulty is using that cartesian query with a form so I can edit the main data table

  10. #10
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Right now my difficulty is using that cartesian query with a form so I can edit the main data table
    I've just seen your other thread!
    If you had said that it needed to be editable, the cartesian join would never have been suggested by ajax!
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  11. #11
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by ridders52 View Post
    I've just seen your other thread!
    If you had said that it needed to be editable, the cartesian join would never have been suggested by ajax!
    Well I can use the cartesian join with the reports (I think) so it displays the empty fields.

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

Similar Threads

  1. Replies: 2
    Last Post: 01-23-2017, 07:06 PM
  2. Replies: 4
    Last Post: 04-10-2014, 06:36 AM
  3. Replies: 5
    Last Post: 03-24-2014, 09:54 AM
  4. Can I make an Outer Join a one way relationship?
    By johnjmcnaughton in forum Programming
    Replies: 19
    Last Post: 05-01-2013, 09:48 AM
  5. Join Statement with two field relationship
    By dhogan444 in forum Queries
    Replies: 2
    Last Post: 08-09-2012, 08:30 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