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
 Transact-SQL (2000)
 query help

Author  Topic 

cognos79
Posting Yak Master

241 Posts

Posted - 2007-05-11 : 12:25:40
I have two tables:
table 1
--------------------------------
empid
1
2


table 2
---------------------------------
empid deptid
1 20
1 21
2 30
2 31
3 40

when i join the two tables on empid i want to retrieve only one record for each empid. It doesnt matter which deptid is pulled.
end result should look like this.

result:
1 20(or 21)
2 30(or 31).

any help

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-05-11 : 12:29:51
[code]
SELECT empid, min(deptid)
FROM Table1 T1
JOIN Table2 T2 ON T1.Empid = T2.EmpId
GROUP BY T1.EmpId
[/code]

Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

cognos79
Posting Yak Master

241 Posts

Posted - 2007-05-11 : 13:23:49
Thanks dinakar
Go to Top of Page
   

- Advertisement -