Solved

How to quiry from the same table 2 times

Posted on 2007-11-23
11
239 Views
Last Modified: 2010-03-20
Hello,

i am trying to write a quiry that has 2 tables.

Table1:
Companies:
Company Name, Manager Name 1, Manager Name 2.
Exampe Data.
Company ABC, 1, 2
Company DEB, 2, 1

Table 2:
Managers:
Manger_ID, Manager_name
Example Data.
1, Alex
2, Peter
3, Stan

Need to create a quiry to Display manager names.

Thanks in advance,

Roman
0
Comment
Question by:dizel247
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
11 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 20341860
Is Manager 1 the same as Manager_Id
0
 

Author Comment

by:dizel247
ID: 20341873
Manager1 and Manger2 - to make it clear Person To manage Sales, Person to manage Purchasing

1 is Manager ID
2 is manager ID

So to answer your question YES Manger 1 is related to managers.manager_id

Thanks in advance,

Roman
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20342357
Based on your input the query will be like as given below.

select * from Companies a, Managers b where a.[Manager Name 1]=b.Manger_ID
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20342360
or as this.
select * from Companies , Managers  where companies.[Manager Name 1]=managers.Manger_ID
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 63 total points
ID: 20342451
dizel247 said:
>>Manager1 and Manger2 - to make it clear Person To manage Sales, Person to manage Purchasing

I would suggest altering your design to something more like:

tblCompanies
----------------------------------------------------------
CompanyID (PK)
CompanyName

tblRoles
----------------------------------------------------------
RoleID (PK)
RoleDescr

tblManagers
----------------------------------------------------------
ManagerID (PK)
LName
FName

tblManagerCompany
----------------------------------------------------------
CompanyID (PK, FK)
ManagerID (PK, FK)
RoleID (FK)

With this structure, you can track additional managers if you need to, without having to alter your
basic design.
0
 

Author Comment

by:dizel247
ID: 20344882
shasund your solution didnt work for some reason.

matthewspatrick, I have though of that the problem is that I have this information updated on the Companies section. If I create the way you mention I will have to update different tables @ the same time. I belive its will be difficult.

Roman
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 20345538
dizel247 said:
>>matthewspatrick, I have though of that the problem is that I have this information updated on the
>>Companies section. If I create the way you mention I will have to update different tables @ the
>>same time. I belive its will be difficult.

Please explain what you mean.  The design I suggested should *eliminate* the need to update more
than one table at a time, because it removes redundant data.
0
 
LVL 25

Assisted Solution

by:imitchie
imitchie earned 62 total points
ID: 20346518

Select A.CompanyName, B.Manager_Name, C.Manager_Name
From Company A
LEFT JOIN Managers B ON B.Manager_ID = A.Manager1_ID
LEFT JOIN Managers C ON C.Manager_ID = A.Manager2_ID

Open in new window

0
 
LVL 1

Expert Comment

by:Computer101
ID: 20962587
Forced accept.

Computer101
Community Support Moderator
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question