Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bostondevin1
Starting Member
1 Post |
Posted - 2009-04-09 : 11:45:07
|
Hello - I am trying to do a query i've never tried before and not sure how I should do it. The query needs to look at three tables:[Projects]id(auto) | projectName1 | 'Project 1'2 | 'Project 2'3 | 'Project 3'[ProjectEmployeesMap]id(auto) | projectID(int) | employeeID(int) 1 | 1 | 22 | 2 | 33 | 1 | 1[Employees]id(auto) | name(nvarchar)1 | Joe2 | Mary3 | SteveI want the query to return 1 record for each Project and I want it to pull in the Top 1 employee into the record somehow. So the resulting records would look like this:1 | 'Project 1' | 'Mary'2 | 'Project 2' | 'Steve'3 | 'Project 3' | '' (return nothing if there isn't one)I think this is a right join - but i'm not sure how I would write it - can anyone help me?Thank you!!! |
|
tosscrosby
Aged Yak Warrior
676 Posts |
Posted - 2009-04-09 : 13:36:09
|
Look up left join and MAX (if that's what you want to use for Top 1 employee) in BOL. We don't do homework here......Terry-- Procrastinate now! |
|
|
dsindo
Starting Member
45 Posts |
Posted - 2009-04-10 : 15:03:56
|
Select a.Projectid, c.projectname, b.name from ProjectEmployeesMap a left join Employees b on a.employeeID=b.idleft join Projects c on a.projectID=c.id |
|
|
|
|
|