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 |
|
godspeedba
Yak Posting Veteran
90 Posts |
Posted - 2010-03-12 : 08:29:50
|
| I have two tables which contain address'. I have been asked to find the total occurence of each town for both databases.I was thinking that I would have to use two temptables to find the town_name and Count(town_name) and then somehow merge the two temptables and the totals into one.What is the best way to approach this? |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-12 : 08:38:19
|
This?select town, count(*) as towncountfrom(select town from DB1.dbo.TownTableUNION ALLselect town from DB2.dbo.TownTable)dtgroup by townorder by town No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
godspeedba
Yak Posting Veteran
90 Posts |
Posted - 2010-03-12 : 08:41:28
|
| Never thought of attempting it in that way, I'll give it a try, thanks webfred |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-03-12 : 12:24:10
|
| Group By state too, else your counts will be wrong.For example, this returns 26 rows in one of my databases:select distinct state from customers where city = 'springfield' |
 |
|
|
|
|
|