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
 General SQL Server Forums
 New to SQL Server Programming
 Query Help

Author  Topic 

DSullSQL
Starting Member

3 Posts

Posted - 2012-04-09 : 13:11:06
I'm wondering if I can write a query to do the following.

A sample set would be like this

PK Account # City
1 1234 NY
2 1234 NY
3 1234 NY
4 1234 NY
5 5678 BOS
6 5678 MINN
7 5678 BOS
8 5678 BOS
9 9012 LA
10 9012 LA

The city should be consistent for entries under a single account number. What I want to do is write a query that will return all the accounts that have inconsistencies in the City column.


Thanks very much,
D

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-04-09 : 13:31:57
SELECT Account
FROM yourTable
GROUP BY Account
HAVING COUNT(Distinct City) > 1

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

DSullSQL
Starting Member

3 Posts

Posted - 2012-04-09 : 13:42:18
Thanks Jim.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-04-09 : 14:34:10
You're welcome.

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -