Solved

How to quiry from the same table 2 times

Posted on 2007-11-23
11
242 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

617 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