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 |
nsuresh316
Starting Member
2 Posts |
Posted - 2013-12-11 : 14:05:36
|
How could I do this efficiently?I have a table with following dataEmpname TeamTest1 MANAGERTest2 TESTERTest3 DEVELOPERTest1 EMER RESPONSETest5 OPERATIONTest6 HOUSEKEEPINGTest7 MANAGERTest5 EMER RESPONSETest9 OPERATIONTest10 EMER RESPONSEI want to get the emp name and team name who is in more than 1 teamFrom our eg. Empname TeamTest1 MANAGERTest1 EMER RESPONSETest5 OPERATIONTest5 EMER RESPONSEalso I want to get the emp name based on the team names which i am mentioningFor eg if i need only Emp name who is a MANAGER and also in EMER RESPONSE team |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2013-12-11 : 14:54:21
|
Here's one way:--emp name and team name who is in more than 1 teamselect Empname, Teamfrom yourTable ytwhere exists (select 1 from yourTable x where x.empname = yt.empname and x.team != yt.team)--only Emp name who is a MANAGER and also in EMER RESPONSE teamselect Empnamefrom yourTable ytwhere exists (select 1 from yourTable x where x.empname = yt.empname and x.team != yt.team and x.Team = 'Manager')and yt.Team = 'Emer Response' Be One with the OptimizerTG |
|
|
nsuresh316
Starting Member
2 Posts |
Posted - 2013-12-11 : 23:31:36
|
Its works Thx |
|
|
|
|
|