If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Please help! - Need Query Statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-28-06, 21:50
chanw1 chanw1 is offline
Registered User
 
Join Date: Sep 2006
Posts: 1
Please help! - Need Query Statement

Hi

I am a newbie at mysql and I need help with a query statement.

I have 2 tables

1. Table of Managers
2. Table of Employees

I need to write a query that will pull all the Managers records and beside each manager display all the employees that they manage. Some manager have manage no employees so they need to display 0.

Please let me know if anyone can help. Thanks in advance. Any help would be much appreciated.
Reply With Quote
  #2 (permalink)  
Old 09-29-06, 06:56
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
sounbds like flaky table design to me
a manager is also an employee, and may also have a manager, ok there are some odd situatuations where a manager may not be employed by the company (could be a contractor or delegate from another organasiation)

the managed by should be a column in the employee table (self referncing FK to employee ID). the manager ID whould be nullable as some mangaers don't have managers (eg directors)

the alternative design is to have a separate table which identifies the entity or role
eg finance dept, accounts payable, receivable etc.... and store a manager there, and associate an employee with a department. that way round when a new manager is appointed its a single change rather than a bulk update of the employee table
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On