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 |
|
simonw2003
Starting Member
11 Posts |
Posted - 2006-01-18 : 06:45:50
|
| I searched the forums and found many topics on removing duplcaites.I need to do the opposite - I'd like to display a list of duplicates for a few tables so that I can then manually decide on how to deal with them (e.g. which table gets to keep the entry. So here is a simplfied version of my problem:- TableA TableB TableC TableD all have a column with phone numbers listed.- I want to return a list of phone numbers which exist more than once, along with their table name. - The phone numbers may not be unique even in their own table.- Not sure it matters but these tables would exist in different sql databases on the same server.Many thanksSimon |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-18 : 07:06:16
|
| Select phoneNo,count(*) as Counting from yourTablegroup by phoneNoMadhivananFailing to plan is Planning to fail |
 |
|
|
simonw2003
Starting Member
11 Posts |
Posted - 2006-01-18 : 07:26:35
|
| Thanks madhivananIm ok with dealing with one table.What about if there are several tables (perhaps 4) which need entries comparing? Thats where I am stuck - if anyone can assist.I guess my end result would be best defined as a list of phonenumbers that appear in more than one table, ideally with the table assocaited names)I dont mind if it requires temp tables. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-01-18 : 09:07:03
|
| Use UNION ALL to union the various tables you need to check together into 1 large resultset. Add a column to label each table's data with their name. Like this:select 'Table 1' as TableName, PhoneNumberfrom Table1union allselect 'Table 2' as tableName, PhoneNumberfrom Table2..etc... |
 |
|
|
|
|
|