Each employee with Manager select [message #342251] |
Thu, 21 August 2008 15:46  |
poratips
Messages: 345 Registered: April 2005 Location: IL
|
Senior Member |
|
|
Hi,
I want to retrieve the data for each employee information with employee manager.
We are storing manager id in other table and employee fname and lname in other table as below.
I am using oracle 9i.
When I write the query i can get mgr_id but i need to know the manager;s first name and last name too.
CREATE TABLE USER
(
USER_ID VARCHAR2(20 BYTE) NOT NULL,
FNAME VARCHAR2(40 BYTE),
LNAME VARCHAR2(40 BYTE),
EMAIL VARCHAR2(80 BYTE),
CONSTRAINT USER_PK PRIMARY KEY (USER_ID),
)
CREATE TABLE EMP
(
USER_ID VARCHAR2(20 BYTE) NOT NULL,
JOB_TITLE VARCHAR2(40 BYTE),
DEPT_CODE VARCHAR2(10 BYTE),
DEPT_DESC VARCHAR2(40 BYTE),
BIRTH_DATE VARCHAR2(35 BYTE),
MGR_ID VARCHAR2(20 BYTE),
ACTIVE_FLAG NUMBER(2),
CONSTRAINT EMP_PK PRIMARY KEY (USER_ID),
FOREIGN KEY (USER_ID)
REFERENCES USER (USER_ID),
)
output will be:
USER_ID User_Fname User_Lname User_Email Emp_Job_Title Emp_Mgr_id Emp_Mgr_Fname||Lname Active_Flag
1 James Adam Ja@abc.com DA 5 Scott Tiger 1
2 John ding jd@abc.com AC 5 Scott Tiger 1
3 Vince dingo vd@abc.com mgr 4 Jeff marsh 1
4 Jeff Marsh jm@abc.com vp 10 Willi goodman 1
10 Willi Goodman wg@abc.com CEO 1
Thanks,
|
|
|
|
Re: Each employee with Manager select [message #342258 is a reply to message #342252] |
Thu, 21 August 2008 16:25   |
poratips
Messages: 345 Registered: April 2005 Location: IL
|
Senior Member |
|
|
Thanks for your prompt response.
I couldn't understand which guidelines i have violated, could you please point it out exactly so i won't make any same mistake next time.
Really appreciate it.
I tried to join but it gives me only mgr_id not manager's name like employee name.
select user_id,fname,lname,email,job_title,mgr_id,mgr_id
from User , emp
where User.user_id = emp.user_id
I need here mgr_id with manager's name which is stored in USER table as fnameand lname.
Thanks,
|
|
|
|
Re: Each employee with Manager select [message #342260 is a reply to message #342259] |
Thu, 21 August 2008 16:44   |
poratips
Messages: 345 Registered: April 2005 Location: IL
|
Senior Member |
|
|
Thanks so much for proper explaination.
I thought it will be simple known emp query so i willnot need full version and also thought that it will be know emp, dept, mgr table structure.
But I am wrong, i should provide full details.
I also mentioned that "When I write the query i can get mgr_id but i need to know the manager's first name and last name too.
"
Which is associated in User table.
Thanks for your help!
|
|
|
|
|
|
Re: Each employee with Manager select [message #342304 is a reply to message #342301] |
Thu, 21 August 2008 23:54  |
rajatratewal
Messages: 507 Registered: March 2008 Location: INDIA
|
Senior Member |
|
|
Anacedent wrote:
Quote: |
select count(*) from dual;
is as useful as the 2 previous posts.
|
Please clarify What's wrong in my post.If i am missing something then please share so that i can learn from it.
Regards,
Rajat
|
|
|