473,416 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How do I dedupe my recordset?

I have just been given the task of learning SQL server at work. I can manage the basics, and I do have a standalone dedupe prog, but tat is pretty slow.

If I have data like this

1. Mr / Smith / 1 Park Road / ME4 2TL / 1 ParkME4 2TL
2. Mr / Brown / 2 Park Road / ME4 2TL / 2 ParkME4 2TL
3. Mrs/ Brown / 2 Park Road / ME4 2TL / 2 ParkME4 2TL

That is a title, surname, address, postcode and a field made of 6 characters of address and the postcode.

I want to be able to dedupe on the final field, so that only one instance of '2 ParkME4 2TL' is left over. It matters not, which instance is deleted, or remains.

I have seen lots of talk of removing duplicates online but it seems to all be about removing a whole duplicated row, or something that would remove both '2 ParkME4 2TL' instances.

Thanks very much :o)
Sep 28 '10 #1
3 6196
gpl
152 100+
Im assuming that the 1. 2. 3. at the start of each row is a unique identifier
Assume your table is called TABLE

Expand|Select|Wrap|Line Numbers
  1. Select t.* from TABLE inner join
  2. (
  3. Select SixChar, Min(ID) as ID
  4. from TABLE t
  5. group by SixChar
  6. ) u
  7. on t.ID=u.ID
The inner query which creates a derived table selects only the unique values of SixChar, along with the lowest value of the ID for that value of SixChar, the join allows you to return the whole row from TABLE that has the same value of ID and SixChar.

It will of course be a bit trickier if you do not have a unique row identifier.

Note that the house number and postcode will uniquely identify an address
Sep 28 '10 #2
That is spot on, thankyou very much!

Within that same bit of code, is it possible to have the 'deduped' data placed into a permanent table? As far as I can see in my SQL studio, the derived table can't be worked on in its own right.
Sep 30 '10 #3
gpl
152 100+
Yes, of course, standard sql allows for this, either
1] you have a table called ddtable with the same structure as TABLE already existing
Expand|Select|Wrap|Line Numbers
  1. Insert ddtable
  2. Select t.* from TABLE inner join 
  3. Select SixChar, Min(ID) as ID 
  4. from TABLE t 
  5. group by SixChar 
  6. ) u 
  7. on t.ID=u.ID
2] if you want to create a table and populate it at the same time
Expand|Select|Wrap|Line Numbers
  1. Select t.* 
  2. INTO ddtable
  3. from TABLE inner join 
  4. Select SixChar, Min(ID) as ID 
  5. from TABLE t 
  6. group by SixChar 
  7. ) u 
  8. on t.ID=u.ID 
the chief difference in the 2 approaches are that with the second one, you can create the table at the same time as filling it.
With the first approach, it will append data to ddtable every time you run it
Sep 30 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tom | last post by:
I want to open a recordset object on an .asp page. When I open the recordset I would like to use a stored procedure that expects a parameter to be passed for the stored procedure. I will then use...
19
by: Adam Short | last post by:
I am trying to write a routine that will connect a .NET server with a classic ASP server. I know the following code doesn't work! The data is being returned as a dataset, however ASP does not...
0
by: CFW | last post by:
I thought this was going to be easy but I'm missing something . . . I need to open an ADODB recordset using the recordset source for a list box on my for. When my form opens, the list box ADODB...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
36
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a...
8
by: Cars | last post by:
Hi, Im trying to dedupe about 30,000 records in a access database, i have done the simple dedupe wizard which has worked, but as you know it only does exact matching dedupes, does anyone , know of...
1
by: asinghy | last post by:
Hello, I am planning to make one dedupe login to find already existing phone numbers in my data base. Details: My database has one table " data" in which i have various fileds including ...
0
ADezii
by: ADezii | last post by:
When you create an ADO Recordset, you should have some idea as to what functionality the Recordset does/does not provide. Some critical questions may, and should, be: Can I add New Records to the...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.