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 |
|
Haggis
Starting Member
2 Posts |
Posted - 2011-01-07 : 15:43:10
|
| Hello,I have been trying to find duplicates between two table. One is a temporary table and the other is a static live database table. This is the SQL I was trying but didn't get the results I expected.SELECT DISTINCTCustomerID,Email,Countryinto #resultsfrom v_corel_tbl_dimension_customer_flat c WITH (readuncommitted)JOIN v_corel_tbl_dimension_registration_flat r ON r.OwnerId = c.CustomerIdWHERE r.ProductType IN ('Upgrade')and r.ProductFamily in ('Productname')and r.productVersion in ('4')Select count(*)from #resultsSelect email, count (*)'dupe_count'into #duplicate_emailsfrom v_corel_tbl_dimension_customer_flat c WITH (readuncommitted)JOIN v_corel_tbl_dimension_registration_flat r ON r.OwnerId = c.CustomerIdWHERE r.ProductType IN ('Upgrade')and r.ProductFamily in ('Productname')and r.productVersion in ('5')group by c.emailAny help on this would be great. |
|
|
RobertKaucher
Posting Yak Master
169 Posts |
Posted - 2011-01-07 : 16:29:45
|
| Ok, I clearly did not understand your question when I wrote my initial reply. Could you post some example data - what do you mean duplicates between two tables? An email exists multiple times in each table? It exists only once but in each table? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-01-08 : 01:08:24
|
| first you need to explain us what you mean by duplicates. Which all fields you consider for identifying duplicates? do you have another unqiue valued field in your table like id column? in any case, posting your table structure with some sample data will really help.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Haggis
Starting Member
2 Posts |
Posted - 2011-01-10 : 07:55:15
|
quote: Originally posted by visakh16 first you need to explain us what you mean by duplicates. Which all fields you consider for identifying duplicates? do you have another unqiue valued field in your table like id column? in any case, posting your table structure with some sample data will really help.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Sorry for not being more specific. I am looking for email addresses that reside in both tables. |
 |
|
|
RobertKaucher
Posting Yak Master
169 Posts |
Posted - 2011-01-10 : 09:54:32
|
| Would a simple join not show you this?I really am having a hard time understanding the question based on the queries you provided...If you can, post the table structure (right clickt he table and select create to new query window and post the scripts) and some dummy data - just make up some data that illustyrates what you have in the DB - as Visakh16 stated, this would help us.===http://www.ElementalSQL.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-01-10 : 10:43:08
|
quote: Originally posted by Haggis
quote: Originally posted by visakh16 first you need to explain us what you mean by duplicates. Which all fields you consider for identifying duplicates? do you have another unqiue valued field in your table like id column? in any case, posting your table structure with some sample data will really help.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Sorry for not being more specific. I am looking for email addresses that reside in both tables.
something likeSELECT email_addressFROM(SELECT email_address,1 AS TblFROM table1UNION ALLSELECT email_address,2 FROM table2)tGROUP BY email_AddressHAVING COUNT(DISTINCT Tbl) =2 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|