MySQL Forums
Forum List  »  Newbie

Can't figure out how to do something...
Posted by: mr_e_uss
Date: February 05, 2007 10:47PM

I am new to (My)SQL -- and I have a question.

I have created a table representing the employees in my company. Each record has an employeeID field (Primary Key, a smallint, that autoincrements), lastName, firstName, etc. Also, each record has a managerID field, which will store the employeeID of the manager of the employee represented by the current row. I'll have the president of the company be his/her own manager.

For example, if the "employees" table looks like this:
employeeID lastName firstName managerID
---------- --------- --------- ---------
1 Boop Betty 1
2 TheCat Felix 1
3 Slate Henry 1
4 Flintstone Fred 3
5 Rubble Barney 3

Then Betty Boop is the president, Felix TheCat and Henry Slate report to her. Fred Flintstone and Barney Rubble report to Henry Slate.

I want to create some queries:
1) SELECT lastName, firstName FROM employees WHERE <manager's lastName is Slate>
2) SELECT <manager's lastName> FROM employees WHERE lastname LIKE rubble
but I do not know how to represent the portions in the "<...>".

In other words, I want to be able to reuse the employeeIDs to indicate the manager, but I also want to be able to map the managerIDs back to their names.

Is this possible?

Options: ReplyQuote


Subject
Written By
Posted
Can't figure out how to do something...
February 05, 2007 10:47PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.