Solved

How to quiry from the same table 2 times

Posted on 2007-11-23
11
235 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
  • 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now