Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old April 27th, 2002, 10:56 AM
torkil torkil is offline
Another damn newb...
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: Bodø, Norway
Posts: 94 torkil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Replace IDs with corresponding names

I have a small tiny problem that I was hoping someone could help me with. Its Oracle... v8

I have a list of employees. Each employee belong to one workgroup, and each workgroup belong to one department. Each workgroup has got a workgroup leader (w_leader) and each department has got a department leader (d_leader). Both w_leader and d_leader are foreign keys that references EmployeeID. With me so far???

Now, I have 3 tables:
Code:
employee (employeeID, name, departmentID)
department (departmentID, name, d_leader)
workgroup (w_leader, employeeID)


With my select query I want to output:
ALL EMPLOYEES
with
- the name of the employee
- the name of the employees workgroup leader
- the name of the employees department leader

Now, with this query:
Code:
SELECT emp.name "EMPLOYEE", wgr.w_leader "WORKGROUP LEADER", dep.d_leader "DEPARTMENT LEADER" 
FROM emplyoees emp, workgroup wgr, department dep  
WHERE emp.employeeID = wgr.employeeID 
AND emp.departmentID = dep.departmentID;


I end out with this output:

Code:
EMPLOYEE   WORKGROUP LEADER   DEPARTMENT LEADER
------------------------------------------------
John    | 1 | 3
Alice   | 1 | 5
Mitch   | 2 | 5


Rather than this:
Code:
EMPLOYEE   WORKGROUP LEADER   DEPARTMENT LEADER
------------------------------------------------
John    | Peter   | Ralph
Alice   | Peter   | Sophie
Mitch   | Kirsten | Sophie



I don't manage to output the NAMES of the workgroup and department leaders, only their IDs. How can I get their names out on that list.... ?
__________________
Torkil Johnsen

Never underestimate the power of stupid people in large groups...
---------------------------(òÓ,)----

Last edited by torkil : April 27th, 2002 at 11:00 AM.

Reply With Quote
  #2  
Old April 27th, 2002, 06:48 PM
Atrus's Avatar
Atrus Atrus is offline
yet another member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 262 Atrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Hi!

Well first of all: You knew that you were getting IDs only, right? You said it yourself:
Quote:
Both w_leader and d_leader are foreign keys that references EmployeeID


So you'll need additional joins to get the names for the IDs.

Code:
SELECT emp.name "EMPLOYEE", emp2.name "WORKGROUP LEADER", emp3.name "DEPARTMENT LEADER"
  FROM emplyoees emp, workgroup wgr, department dep, emplyoees emp2, emplyoees emp3
 WHERE emp.employeeID = wgr.employeeID
   AND emp.departmentID = dep.departmentID
   AND wgr.w_leader = emp2.employeeID
   AND dep.d_leader = emp3.employeeID;


I hope I didn't make any serious mistakes here. That query is untested :-)


Regards,

Atrus.
__________________
Webmaster - Stefan Meier KG TABAKWAREN - Pfeifen, Premium-Zigarren, ... (_Ger)

Reply With Quote
  #3  
Old April 29th, 2002, 02:16 AM
torkil torkil is offline
Another damn newb...
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: Bodø, Norway
Posts: 94 torkil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Ahhh....

Genious. Additional joins with additional table aliases. Brilliant

Yes I knew I was only going to get ID's.

Reply With Quote
  #4  
Old April 29th, 2002, 09:02 AM
Atrus's Avatar
Atrus Atrus is offline
yet another member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 262 Atrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Hi!

"What an honour!" (Zoidberg)

Atrus.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Replace IDs with corresponding names


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway