473,408 Members | 2,477 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,408 software developers and data experts.

Delete Duplicated Rows

ahmedtharwat19
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 2862
NeoPa
32,556 Expert Mod 16PB
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,556 Expert Mod 16PB
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
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 Expert 2GB
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,556 Expert Mod 16PB
Ah well Linq my friend. I'm still sane aren't I.
Jun 6 '10 #6
NeoPa
32,556 Expert Mod 16PB
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
@NeoPa
yes, thank you for all.
Jun 7 '10 #8
missinglinq
3,532 Expert 2GB
@NeoPa
I'm sure you are, Ade, but apparently some are not!

Linq ;0)>
Jun 7 '10 #9
@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
NeoPa
32,556 Expert Mod 16PB
missinglinq: I'm sure you are, Ade, but apparently some are not!
I'd hate to be confused with someone who thought that way ;)
Jun 8 '10 #11
NeoPa
32,556 Expert Mod 16PB
ahmedtharwat19: i`m sorry idont understand what do you mean , i just add this for that thread to complete the thread in same problem.
I'm happy to explain :)

Generally, a thread is focused around the problem of the Original Poster (or OP). Answers of many varieties are encouraged. Further questions that are likely to take the focus away from the OP's requirements are considered unwelcome (they are against the rules in fact). In this case, your post was directing the thread away from the OP's question and onto your requirements. That is a hijack.

That said, we don't wish you to go unsupported, we simply want to keep the structure clean. You can post your question in it's own thread (as we now have) and all should be well.

I hope that makes it clearer for you.
Jun 8 '10 #12
thank you,

i`m sorry my english is not good. i think it very bad.

but i have a problem in this site because i add the thread

title:create a module via vba in current database or in another database

but kub365 was delete it , he think it`s a Homework/Coursework.

I`m an Accountant From 2001, and the vba(ms access) is just my hoppy.

please help me !!??..

(medo)
Jun 8 '10 #13

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

Similar topics

3
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...
1
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...
1
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 ...
0
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...
16
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...
9
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...
6
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...
2
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.