dbTalk Databases Forums  

Help with query join problem

comp.databases.ms-access comp.databases.ms-access


Discuss Help with query join problem in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
KC-Mass
 
Posts: n/a

Default Help with query join problem - 01-29-2009 , 09:44 AM






I have 4 Access production tables each with two production indicators
and each with an employeeID and a WeekOfYear (eg 2008-09) field. I
want to join them in a query such that I get one line for each
employeeID - WeekOfYear combination and have the 8 production
indicators all in the same record. The problem is that each employee
does not work in each production area every week and so some
employeeID - WeekOfYear combinations exist in some tables and not in
others. The typical joins then always seem to leave some data behind.

I want to end up with something like:

EmployeeID WeekOfYear PI1 PP2 PI3 PI4
a432 2008-11 17
21 87

The blank is ok.

Any ideas on getting them all to come into the query.

Thanks
Kevin

Reply With Quote
  #2  
Old   
Roger
 
Posts: n/a

Default Re: Help with query join problem - 01-29-2009 , 10:04 AM






On Jan 29, 8:44*am, KC-Mass <connear... (AT) comcast (DOT) net> wrote:
Quote:
I have 4 Access production tables each with two production indicators
and each with an employeeID and a WeekOfYear (eg 2008-09) field. *I
want to join them in *a query such that I get one line for each
employeeID - WeekOfYear combination and have the 8 production
indicators all in the same record. *The problem is that each employee
does not work in each production area every week and so some
employeeID - WeekOfYear combinations exist in some tables and not in
others. *The typical joins then always seem to leave some data behind.

I want to end up with something like:

EmployeeID * * * *WeekOfYear * * * PI1 * * *PP2 * PI3 * * PI4
a432 * * * * * * * * * * 2008-11 * * * * * * * 17
21 * * * * * * * * 87

The blank is ok.

Any ideas on getting them all to come into the query.

Thanks
Kevin
If you have a weekOfYear table, you can build a cross-product query
select employeeId, weekOfYear from tblEmployee,tblWeekOfYear

to give you all combinations that you can use with other queries


Reply With Quote
  #3  
Old   
Rich P
 
Posts: n/a

Default Re: Help with query join problem - 01-29-2009 , 10:08 AM



Greetings,

If you could show some samples of your source data - the data the works
as you desire and some samples of the data which doesn't work as desired
(at least a few records - a few fields) -- then show a sample of what
you want the result set to look like to include the data which works and
the data which does not work (right now) (show at least a few records) -
it would be easier to provide some suggestions what you could do to make
it happen like that.


Rich

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #4  
Old   
KC-Mass
 
Posts: n/a

Default Re: Help with query join problem - 01-29-2009 , 10:30 AM



On Jan 29, 11:04*am, Roger <lesperan... (AT) natpro (DOT) com> wrote:
Quote:
On Jan 29, 8:44*am, KC-Mass <connear... (AT) comcast (DOT) net> wrote:



I have 4 Access production tables each with two production indicators
and each with an employeeID and a WeekOfYear (eg 2008-09) field. *I
want to join them in *a query such that I get one line for each
employeeID - WeekOfYear combination and have the 8 production
indicators all in the same record. *The problem is that each employee
does not work in each production area every week and so some
employeeID - WeekOfYear combinations exist in some tables and not in
others. *The typical joins then always seem to leave some data behind..

I want to end up with something like:

EmployeeID * * * *WeekOfYear * * * PI1 * * *PP2 *PI3 * * PI4
a432 * * * * * * * * * * 2008-11 * * * * * * * 17
21 * * * * * * * * 87

The blank is ok.

Any ideas on getting them all to come into the query.

Thanks
Kevin

If you have a weekOfYear table, you can build a cross-product query
* select employeeId, weekOfYear from tblEmployee,tblWeekOfYear

to give you all combinations that you can use with other queries
Roger

Does that WeekOfYear table need only the weekOfYear field?

Thanks Kevin


Reply With Quote
  #5  
Old   
KC-Mass
 
Posts: n/a

Default Re: Help with query join problem - 01-29-2009 , 10:49 AM




Hi Rich
Thanks for your time. Here's sample data
If I join on Give me everything from Tbl1 and all matching from Tbl2
I will lose Rec2 of Tbl2. If I join on give me everything in Tbl2 and
matches from Tbl1, I will lose Rec2 and Rec3 of Tbl1.
If I join on give me everything that matches in both, I will lose
Rec2 and Rec3 of Tbl1 and Rec2 of Tbl2.


Tbl1
Rec1 - ca112, 2008-10, 14,43
Rec2 - ca112, 2008-11, 23,56
Rec3 - cb321, 2008-14, 32,54

Tbl2
Rec1 - ca112, 2008-10, 7, 2
Rec2 - cb321, 2008-13, 12,32

Hope this helps



On Jan 29, 11:08*am, Rich P <rpng... (AT) aol (DOT) com> wrote:
Quote:
Greetings,

If you could show some samples of your source data - the data the works
as you desire and some samples of the data which doesn't work as desired
(at least a few records - a few fields) -- then show a sample of what
you want the result set to look like to include the data which works and
the data which does not work (right now) (show at least a few records) -
it would be easier to provide some suggestions what you could do to make
it happen like that.

Rich

*** Sent via Developersdexhttp://www.developersdex.com***


Reply With Quote
  #6  
Old   
Rich P
 
Posts: n/a

Default Re: Help with query join problem - 01-29-2009 , 02:27 PM



Hi Kevin,

Try something like this:

Select t1.*, t2.* from Tbl1 t1 left Join Tbl2 t2 on t1.JoinField =
t2.JoinField

This will return all records from Tbl1 and only the records which match
in Tbl2 by using the "Left Join" operation If you switch the tables
around then you would get all recs from Tbl2 and only the recs from Tbl1
which match.

I wasn't clear exactly what data you wanted to retrieve. If you want
everything from Tbl1 and Tbl2 you can use a union query.

Rich

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.