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
 Non matching column values in the same table

Author  Topic 

rahamanf
Starting Member

15 Posts

Posted - 2008-03-22 : 03:20:25
I need to write a statement that returns the name, city, and state of each vendor that’s located in a unique city and state. In other words, I can not include vendors that have a city and state in common with another vendor.

Any help?
Thanks.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-22 : 04:59:36
Using SQL Server 2000 or SQL Server 2005?

SELECT t1.*
FROM Table1 AS t1
INNER JOIN (SELECT City, State from Table1 GROUP BY City, State HAVING COUNT(*) = 1) AS t2
ON t2.City = t1.City AND t2.State = t1.State



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

rahamanf
Starting Member

15 Posts

Posted - 2008-03-22 : 11:35:41
Thanks very much Peso, It works.
Go to Top of Page
   

- Advertisement -