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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-01-24 : 08:36:48
|
| Dave writes "Hi guys, Ok, perhaps I left my brain at home today but I cant seem to figure out how to write the following query:I have a table (use Northwinds for example), where I want to find Employees who represent territories (NY and IL for example) - The table structure is basic: EmployeeId, TerritoryIdThe select I have written wont work because the TerritoryId cant be ANDed, eg: Select EmployeeId FROM EmployeeTerritory WHERE TerritoryId='NY' AND TerritoryId='IL' << this cant work, it' illogical... so I do I structure a query that will return the employees who have BOTH territories in their portfolio, not just one. I have a feeling I am going to have to use HAVING...Thanks a lotDavid." |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-24 : 08:48:28
|
| Try thisSelect EmployeeId FROM EmployeeTerritory WHERE TerritoryId in('NY','IL')group by EmployeeId having count(*)=2MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|