?
Solved

Self-Join

Posted on 2011-02-24
3
Medium Priority
?
494 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

762 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