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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 select all the same address

Author  Topic 

ntn104
Posting Yak Master

175 Posts

Posted - 2011-10-26 : 11:58:29
Hello,

How do I write sql statement to select all accounts that have the same address (multiple accounts the same address)
for example:

account 123, 345, 678 can have the same address as:
12th street
Philadelphia, pa 19012

I tried the following sql statement, but return zero row...but it should have a lot...

select id, address1
from table1
group by ssn, address1
having (count(address1)>1)

Thanks,

X002548
Not Just a Number

15586 Posts

Posted - 2011-10-26 : 12:46:01
SELECT * FROM table1 WHERE address1 IN (SELECT address1 FROM table1 GROUP BY address1 HAVING COUNT(*) > 1)

???

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2011-10-26 : 13:17:15
Thanks Much!!!....It worked with your way....

quote:
Originally posted by X002548

SELECT * FROM table1 WHERE address1 IN (SELECT address1 FROM table1 GROUP BY address1 HAVING COUNT(*) > 1)

???

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/




Go to Top of Page
   

- Advertisement -