Click here to Skip to main content
15,904,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two table as mentioned EQDUMP and HRISDetails as:-

EQDump table as:-
ECode Ename
1 A
2 B
3 C
4 D

HRISDetails Table as:-
ECode EName managername
1 A E
2 B E
3 C F
4 D F
5 E G
6 F G

I need a query which gives me the field Empname from EqDump,Ename from EQDUmp and ManagerEmpID from HRISDetails.
The Out put should be look like this:-

ECode Ename MCode
1 A 5
2 B 5
3 C 6
4 D 6

Note:- Manager EmplyoeeID i.e MCODe is extracted from HRIS Details Table.You can find that the manager name for Emplyoee 'A" is 'E' and 'E' ECode is 5 so in the output we have to display the ECOde for Employee, Employeename and the ECODe of Manager.

Please provide me the query if possible as the guys who are working on database side is on leave and i only have to write this on urgent basis:(
Posted

hi,

You can use this perfect query

SELECT HRISDetails.Ecode, HRISDetails.Ename AS EName, EQDump.Ecode AS MCode
FROM HRISDetails INNER JOIN
EQDump ON HRISDetails.Managername = EQDump.Ename
 
Share this answer
 
v4
Comments
Tarakeshwar Reddy 20-Jan-12 0:45am    
Have you tried the solution? It will not return any rows. HRISDetails has manager name of E, F and G, whereas EQDump table does not have those rows. Look at my solution posted.
amolpatil2243 20-Jan-12 0:53am    
i wrote the solution because of every manager is a employee and he listed in employee table
Try this:

SQL
select e.Ecode, e.Ename , hh.Ecode as Mcode   from EQDump e
join HRISDetails h on e.Ename = h.Ename
join HRISDetails hh on h.managername = hh.ename


Output:

ECode Ename MCode
1 A 5
2 B 5
3 C 6
4 D 6
 
Share this answer
 
Comments
Tarakeshwar Reddy 20-Jan-12 0:48am    
Looks like we both posted at the same time. 5'ed your solution
Om Prakash Pant 20-Jan-12 0:53am    
yes :-)
i was looking at multiple posts of same question
SQL
select A.EmployeeName,A.Ecode,B.ECode as ManagerECode from HRISDetails as A inner join
HRISDetails as B on
A.ImmediateSupervisor=B.EmployeeName where A.Ecode in (Select SUBSTRING(ReporteeUserID,4,8) from EQDump)
 
Share this answer
 
SQL
select EQDump.ECode, EQDump.EName, HRIS2.Ecode as MCode
From EQDump
inner join HRISDetails HRIS1 on EQDump.ECode = HRIS1.ECode
inner join HRISDetails HRIS2 on HRIS1.managername = HRIS2.EName
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900