Solved

Self-Join

Posted on 2011-02-24
3
488 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now