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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Get top 3 from another table into my single SELECT

Author  Topic 

jhilb
Starting Member

22 Posts

Posted - 2001-04-02 : 12:22:17
I want to do a select, then for every record in that select I want to get the "top 3" from another table. Except I want it all to be in a single statement and return a single row per employee.

So, I've got a table called employee which contains records of employee and another table called projects.

Here's the employee table Project table

EmpId EmpName Projd EmpId ProjName
------------------------- -------------------------
1 John 55 1 ABCD
2 Betty 56 2 EFGH
3 Frank 57 1 IJHQ

I want results like this:

EmpId EmpName ProjName1 ProjName2 ProjName3
-------------------------------------------------------
1 John ABCD IJHQ
2 Betty EFGH
3 Frank

Can't figure out how to do it in a single run at the database.


   

- Advertisement -