473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

many to many join

I have posted this question in other forums, but no one seems to be able to solve this problem. I have 2 tables - one called tblCompanyA, the other called tblCompanyB. The layouts are the same: JobCode, Name, Title. JobCode is 5 positions, alphanumric. Company A and B share many of the same jobcode numbers. However, the are some jobcodes in A that are not in B and some jobcodes in B that are not in A. I would like to create a query that would display the results side by side.
Example:

Company A Company B
JobCode Name Title JobCode Name Title
0630 smith vp 0630 jones vp
0630 bailey vp 0630 johnson vp
0630 white vp
0631 moses avp
0632 brown fvp
0633 madison tr
0634 mason xyz 0634 perry zsw

How can I do this?
Thanks.
Jul 26 '07 #1
7 1967
I have posted this question in other forums, but no one seems to be able to solve this problem. I have 2 tables - one called tblCompanyA, the other called tblCompanyB. The layouts are the same: JobCode, Name, Title. JobCode is 5 positions, alphanumric. Company A and B share many of the same jobcode numbers. However, the are some jobcodes in A that are not in B and some jobcodes in B that are not in A. I would like to create a query that would display the results side by side.
Example:

Company A Company B
JobCode Name Title JobCode Name Title
0630 smith vp 0630 jones vp
0630 bailey vp 0630 johnson vp
0630 white vp
0631 moses avp
0632 brown fvp
0633 madison tr
0634 mason xyz 0634 perry zsw

How can I do this?
Thanks.

i presume you mean that there are 2 separate companies and they may or mauy not have the same jobcodes, and it just so happens that in this case many of them are the same. i notice that jobcode 0634 has 2 different titles. are these 2 different jobs in 2 different companies with the coincidentally the same jobcode.

you could use a union query to solve this - query1 UNION query2 - where query1 selects from tblCompanyA and query2 from tblCompanyB. as long as you select the same number of fields in each query it will work.

any recordsets you create using this query wont be updatable though.


Pete
Jul 26 '07 #2
i presume you mean that there are 2 separate companies and they may or mauy not have the same jobcodes, and it just so happens that in this case many of them are the same. i notice that jobcode 0634 has 2 different titles. are these 2 different jobs in 2 different companies with the coincidentally the same jobcode.

you could use a union query to solve this - query1 UNION query2 - where query1 selects from tblCompanyA and query2 from tblCompanyB. as long as you select the same number of fields in each query it will work.

any recordsets you create using this query wont be updatable though.


Pete
My mistake on the title - should be the same. When I try what you suggest, I get a cartesian product and now my file has many thousands of records. I've read in other forums that I should create a third "join" table to eliminate this problem - but I do not know how to make it work.
Jul 26 '07 #3
My mistake on the title - should be the same. When I try what you suggest, I get a cartesian product and now my file has many thousands of records. I've read in other forums that I should create a third "join" table to eliminate this problem - but I do not know how to make it work.
on the title - what should be the same? i am now confused as to what your actual problem is as there does not appear to be any data requiring a join table.

can you post your database structure? if in access a screenshot of the relationships diagram?

Pete
Jul 26 '07 #4
on the title - what should be the same? i am now confused as to what your actual problem is as there does not appear to be any data requiring a join table.

can you post your database structure? if in access a screenshot of the relationships diagram?

Pete
I am trying to do a side by side comparison of jobs at the two companies. Many job codes will match but the number of people in those positions can vary. In other cases, the job appears in company a but not company b - or in company b but not a. The final result should be a list of all positions in both companies with all matches and all unmatched.
Jul 26 '07 #5
I am trying to do a side by side comparison of jobs at the two companies. Many job codes will match but the number of people in those positions can vary. In other cases, the job appears in company a but not company b - or in company b but not a. The final result should be a list of all positions in both companies with all matches and all unmatched.
starting to see what you mean. you could run 2 separate queries and process the results so they display with gaps between the rows where appropriate.

what you want is a query that returns its results into a set of fields in another query that is then grouped by jobcode. i'm not sure if this can be done but the only way i can think of is by a nested query, though i have never used one sorry. what you want might be:

SELECT tblCompanyA.Jobcode as JobcodeA, {SELECT tblCompanyB.Jobcode as JobcodeB FROM tblCompanyB} FROM tblCompanyA GROUP BY tblCompanyA.Jobcode

i don't think that will work but it seems thats the knind of think you want to do


Pete
Jul 26 '07 #6
starting to see what you mean. you could run 2 separate queries and process the results so they display with gaps between the rows where appropriate.

what you want is a query that returns its results into a set of fields in another query that is then grouped by jobcode. i'm not sure if this can be done but the only way i can think of is by a nested query, though i have never used one sorry. what you want might be:

SELECT tblCompanyA.Jobcode as JobcodeA, {SELECT tblCompanyB.Jobcode as JobcodeB FROM tblCompanyB} FROM tblCompanyA GROUP BY tblCompanyA.Jobcode

i don't think that will work but it seems thats the knind of think you want to do


Pete
This is a vexing problem that no one seems able to solve. Thanks for your suggestion. I will give it a try.
Jul 26 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Try this ...
Expand|Select|Wrap|Line Numbers
  1. SELECT A.JobCode As JobCodeA, A.Name As NameA, A.Title As TitleA, B.JobCode As JobCodeB, B..Name As NameB, B.Title As TitleB
  2. FROM tblCompanyA As A INNER JOIN tblCompanyB As B
  3. ON A.JobCode  = B.JobCode 
  4. UNION
  5. SELECT A.JobCode As JobCodeA, A.Name As NameA, A.Title As TitleA, "" As JobCodeB, "" As NameB, "" As TitleB
  6. FROM tblCompanyA As A LEFT JOIN tblCompanyB As B
  7. ON A.JobCode  = B.JobCode
  8. WHERE B.JobCode Is Null
  9. UNION
  10. SELECT "" As JobCodeA, "" As NameA, "" As TitleA, B.JobCode As JobCodeB, B..Name As NameB, B.Title As TitleB
  11. FROM tblCompanyA As A RIGHT JOIN tblCompanyB As B
  12. ON A.JobCode  = B.JobCode
  13. WHERE A.JobCode Is Null
  14.  
This should give all jobs from both tables.
Aug 6 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
2
by: Keith | last post by:
I am having a problem creating a many-to-many-to-many type relationship. It works fine, but when I create a view to query it and test it, it does not generate the results I expected. Below...
3
by: Jack Smith | last post by:
Hello, I want to be able to view data from 3 tables using the JOIN statement, but I'm not sure of how to do it. I think i don't know the syntax of the joins.I imagine this is easy for the...
4
by: Fred | last post by:
Hi. What is the usual and what are the possible fields to use for the primary key of an intersecting table of a many-to-many relationship? I would think the typical, most common fields would...
1
by: Phil W | last post by:
Hello, I have set up my database in access using many to many relationships (it's the good ol' books and authors one again). I've actually extended it to include other people who contribute in...
4
by: Apple | last post by:
I have to create a query with many to many relationship, but I can't break it into 2 x 1 to many, should there anyone can teach me how to solve this problem. Thanks in advance!
0
by: someone | last post by:
Having problem with many to many join. Below is the schema with tables and sql statements. All seems to work with the following exception: Can not get all the field names to display. //...
2
by: John1975 | last post by:
OS: XP MS Access 2007 Having some trouble with a join. I have three tables: progress_reports, clippership_archives, and employee conversion progress_reports: id emp_id
6
nathj
by: nathj | last post by:
Hi, I've been puzzling out the problem below for several hours and it's driving me mad. I know there is a way to do what I want I just can't figure it out. Here's the situation. I have the...
2
by: Neekos | last post by:
Im working on web tool that will allow supervisors to see a list of their agents and their call stats for a call center. I have one main table that holds employee IDs and their supervisor names....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.