Thursday, August 11, 2011

SQL JOINS examples 4

 I have a 'Emp' table like
Empid Fname Lname Mgrid
1 x Last x
2 First x 1
Want to join and the result should be like "First Last" in one row

Tried with the query like,
"Select Distinct A.Fname, B.Lname
From Emp A join Emp B
on A.Mgrid = B.Empid"
or
"Select Distinct A.Fname, B.Lname
From Emp A, Emp B
where A.Mgrid = B.Empid"
or
"Select Distinct A.Fname, B.Lname
From Emp A
Left join Emp B on A.Mgrid = B.Empid"

but getting the results like,
First Last
First

Can any one help in removing the second row from the results?