Solved

Self-Join

Posted on 2011-02-24
3
491 Views
Last Modified: 2012-06-22
Need help with the following:

Display the employee's last name and employee number along with the manager's last name and manager_number.

This is what I have but it returns: no statement parsed

Select worker.last_name, worker.emloyee_id, manager.last_name, manager.manager_id
From employees worker, employees manager
Where worker.manager_id = manager.employee_id

Any suggestions would be helpful
0
Comment
Question by:dc0819
  • 2
3 Comments
 
LVL 4

Expert Comment

by:mawni
ID: 34972537
Select
worker.last_name,
worker.emloyee_id,
manager.last_name,
manager.manager_id
From employees worker,
employees manager
Where
worker.manager_id = manager.employee_id;

yes what you did solves your problem, but I think you must use distinct or group by employee ID, because I am sure that there are many employees that shares the same manager!
0
 
LVL 5

Accepted Solution

by:
jaiminpsoni earned 500 total points
ID: 34973491
Select worker.last_name, worker.employee_id, manager.last_name, manager.employee_id
From employees worker, employees manager
Where worker.manager_id = manager.employee_id
0
 
LVL 5

Expert Comment

by:jaiminpsoni
ID: 34973538
From your query....
Select worker.last_name, worker.emloyee_id, manager.last_name, manager.manager_id

you dont need id of manager's manager, right? if you need id of employee, get manager.employee_id

@mawni,
"you must use distinct or group by employee ID"
Why would we need to do group by? We are not usign any group function here. Are we?
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
string fuctions 4 28
sql help 2 46
sql server query 12 26
How to structure query with count aggregate 4 19
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question