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 |
itay
Starting Member
6 Posts |
Posted - 2011-03-06 : 04:38:26
|
Hello,I have a table with these columns : PersonID, FirstName, LastName.I need to get all the PersonID's that have all these last names: 'aaa', 'bbb', 'ccc'.The table looks like this:PersonId LastName FirstName1 aaa ddd 1 bbb fff 1 ccc eeeeThanks. |
|
malpashaa
Constraint Violating Yak Guru
264 Posts |
Posted - 2011-03-06 : 05:14:45
|
Try this:SELECT PersonId FROM TableName WHERE LastName IN('aaa', 'bbb', 'ccc') GROUP BY PersonIdHAVING COUNT(DISTINCT LastName) = 3; |
 |
|
itay
Starting Member
6 Posts |
Posted - 2011-03-06 : 06:16:04
|
Perfect. Thanks. |
 |
|
malpashaa
Constraint Violating Yak Guru
264 Posts |
Posted - 2011-03-06 : 06:47:16
|
Welcome. |
 |
|
|
|
|