Solved

How to quiry from the same table 2 times

Posted on 2007-11-23
11
240 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
Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 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