473,799 Members | 3,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete Duplicated Rows

ahmedtharwat19
55 New Member
hi, every one

for delete duplicated rows can any one up to us an example to see that

because i`m beginning to ms access

and i have a problem about that

thank you for all
abo mroan
Nov 15 '09 #1
12 2896
NeoPa
32,579 Recognized Expert Moderator MVP
When posting your question it is necessary to put it in its own thread. Hijacking somebody else's (Delete Duplicate records) is not acceptable. It is acceptable to post a link if you think it's relevant though. I have split it away for you (and included a link across), but please remember in future.
Nov 15 '09 #2
NeoPa
32,579 Recognized Expert Moderator MVP
If you had read the previous thread you would have seen that posts #9 & #10 have examples of code for this job. Unfortunately, as you haven't explained what you need other than very generally, I cannot say how well suited either is for your needs. In case it helps though (and for anyone finding this in a search) I will include my code from Post #10 of Delete Duplicate records.

This code assumes a table in the local db but it can be tweaked or enhanced.
For instance, if the one to be kept must have the lowest Primary Key value then it could be changed to do that.
Expand|Select|Wrap|Line Numbers
  1. 'DelDups Removes duplicate records in strTable matched on strField
  2. Public Sub DelDups(strTable As String, strField As String)
  3.     Dim strSQL As String, varLastVal As Variant
  4.  
  5.     'Recordset must be full table but sorted by the field we're checking
  6.     strSQL = "SELECT * FROM [" & strTable & "] ORDER BY [" & strField & "]"
  7.     With CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
  8.         varLastVal = Null
  9.         'For each record, check against previous value in strField
  10.         'If same then this is a duplicate so can be removed
  11.         Do Until .EOF
  12.             If .Fields(strField) = varLastVal Then
  13.                 Call .Delete
  14.             Else
  15.                 varLastVal = .Fields(strField)
  16.             End If
  17.             Call .MoveNext
  18.         Loop
  19.     'Ending the 'With' releases the Recordset
  20.     End With
  21. End Sub
Hope it helps.
Nov 15 '09 #3
ahmedtharwat19
55 New Member
Mr NeoPa

it`s a perfect code thank you very much

but what the condition if there 2 fields

i try it and it work as well

Expand|Select|Wrap|Line Numbers
  1. 'DelDups Removes duplicate records in strTable matched on strField
  2. Public Function DelDups(strTable As String, strField As String, strField1 As String)
  3.     Dim strSQL As String, varLastVal As Variant, varLastVal1 As Variant
  4.  
  5.     'Recordset must be full table but sorted by the field we're checking
  6.     strSQL = "SELECT * FROM [" & strTable & "] ORDER BY [" & strField & "] , [" & strField1 & "]"
  7.     With CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
  8.         varLastVal = Null
  9.         varLastVal1 = Null
  10.  
  11.         'For each record, check against previous value in strField
  12.         'If same then this is a duplicate so can be removed
  13.         Do Until .EOF
  14.             If .Fields(strField) = varLastVal And .Fields(strField1) = varLastVal1 Then
  15.                 Call .Delete
  16.             Else
  17.                 varLastVal = .Fields(strField)
  18.                 varLastVal1 = .Fields(strField1)
  19.  
  20.             End If
  21.             Call .MoveNext
  22.         Loop
  23.     'Ending the 'With' releases the Recordset
  24.     End With
  25. End Function
thank you
Jun 6 '10 #4
missinglinq
3,532 Recognized Expert Specialist
When posting your question it is necessary to put it in its own thread. Hijacking somebody else's (Delete Duplicate records) is not acceptable.
Careful, NeoPa! You appear to be discipling someone in public!

Linq ;0)>
Jun 6 '10 #5
NeoPa
32,579 Recognized Expert Moderator MVP
Ah well Linq my friend. I'm still sane aren't I.
Jun 6 '10 #6
NeoPa
32,579 Recognized Expert Moderator MVP
ahmedtharwat19: but what the condition if there 2 fields

i try it and it work as well
Indeed. It seems you have understood the concept well enough to modify it for slightly changed circumstances.

Well done :)
Jun 6 '10 #7
ahmedtharwat19
55 New Member
@NeoPa
yes, thank you for all.
Jun 7 '10 #8
missinglinq
3,532 Recognized Expert Specialist
@NeoPa
I'm sure you are, Ade, but apparently some are not!

Linq ;0)>
Jun 7 '10 #9
ahmedtharwat19
55 New Member
@NeoPa
i`m sorry idont understand what do you mean , i just add this for that thread to complete the thread in same problem.

Generally, thank you for an advice.

Best Regards ,
Medo
Jun 7 '10 #10

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

Similar topics

3
2869
by: Mirek Rusin | last post by:
....what is the best way to force duplicated unique or primary key'ed row inserts not to raise errors? duplicated rows can be ignored or updated as well - it really doesn't matter. to be specific, i've got: $ psql -d mydb -c "copy mytable from 'mytable.tsv'
1
8907
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB automatically deletes also all those rows in the child table whose foreign key values are equal to the referenced key value in the parent row. However:
1
10810
by: Patrizio | last post by:
Hi All, I've the following table with a PK defined on an IDENTITY column (INSERT_SEQ): CREATE TABLE MYDATA ( MID NUMERIC(19,0) NOT NULL, MYVALUE FLOAT NOT NULL, TIMEKEY INTEGER NOT NULL, TIMEKEY_DTTM DATETIME NULL,
0
1061
by: GlobalBruce | last post by:
The GAC on my development computer has several assemblies which are duplicated. For instance, the System assembly is present as two different native images as well as the non-native version. The native images differ by date/time stamp -- although they are only different by 3 days during Feb/2004. Many of the System assemblies have similar duplicated native images. Why are there multiple copies of these assemblies? Is it safe, useful,...
16
3877
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the table, or perhaps bytes, being updated where the engine just decides, screw it, i'll just make a new one. surfed this group and google, but couldn't find anything. the context: we have some java folk who like to parametize/
9
2799
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like this: id Name Surname pictr0 picrt1 pictr2 pictr3
6
1645
by: Ryan Liu | last post by:
Hi, If I have tens of thousands DataRow in a DataTable and allow the end user to pick any DataColumn(s) to check for duplicated lines, the data is so large, is there a better API, algorithm can be used for this purpose? Thanks a lot! Ryan
2
5425
by: Radu | last post by:
Hi. I have a "union" table which results of a union of two tables. Occasionally I could have duplicates, when the same PIN has been added to both tables, albeit at different Datees/Times, such as: PIN Name Added Date 100411 A 7/11/2007 10:12:58 AM 100411 A 7/17/2007 10:54:23 AM 100413 B 7/11/2007 10:13:28 AM
3
12348
by: Michel Esber | last post by:
Hello, Environment: DB2 LUW v8 FP15 / Linux I have a table with 50+ Million rows. The table structure is basically (ID - Timestamp). I have two main applications - one inserting rows, and the other reading/deleting rows. The 'deleter' application runs a MIN/MAX (timestamp) for each ID and, if the difference between min/max is greater than 1h, it reads all
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10247
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10023
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7561
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.