Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL question

Status
Not open for further replies.

gunsva

Technical User
Aug 23, 2001
6
US
Is this possible with plain SQL ? I have the following source table definition :
employee_name employee_manager_id
jack Bill
jack Gates
jill Ellison
An employee can have a max of 2 records in the source table

I need the following in the target table
employee_name employee_manager_1 employee_manager_2
jack Bill Gates
jill Ellison <NULL>

Can I achieve this using plain SELECT statements on the source table ? Thanks!
 
Since you only have a max of 2 records per employee, you could take advantage of the ascii comparison of the MIN and MAX function.

Code:
SELECT   employee_name, 
         MIN(employee_manager_id)  employee_manager_1, 
         MAX(employee_manager_id)  employee_manager_2
FROM     source_table
GROUP BY employee_name
 
I think you need 'as' :

MIN(employee_manager_id) as employee_manager_1

Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
ahhhh, thanks for the insight!

Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top