473,395 Members | 1,689 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,395 software developers and data experts.

delete reverse duplicates

Hi,
I have a table with related values. Sometimes there are records with the reverse relation. I want to delete those but dont know how to handle this. eg:
table with two columns :
A-B
A-C
A-D
A-E
B-C
B-E
F-G
C-A
C-D

In the example above C-A is the record I want deleted because it is the reverse record of A-C already in the list.
How can I do this using access Queries ?

Thanx
Apr 8 '16 #1
4 1056
ok,i think this does it..
Expand|Select|Wrap|Line Numbers
  1. SELECT E1, E2
  2. FROM Table1
  3. WHERE E1<=E2
  4. UNION
  5. SELECT E2, E1
  6. FROM Table1
  7. WHERE E1>E2
Apr 9 '16 #2
NeoPa
32,556 Expert Mod 16PB
I doubt it would actually. I'm not sure it even, reliably, returns the records you want without those items you've described.

A DELETE query has to work on an updatable data source. Once UNION is used in Jet/ACE the data source becomes non-updatable.

I assume that your data is actually stored as two separate fields ([E1] & [E2]), rather than a string as originally shown. If so then the following should probably work :
Expand|Select|Wrap|Line Numbers
  1. DELETE [tA].*
  2. FROM   [TableName] AS [tA]
  3.        INNER JOIN
  4.        [TableName] AS [tB]
  5.   ON   ([tA].[E1]=[tB].[E2])
  6.  AND   ([tA].[E2]=[tB].[E1])
  7. WHERE  ([tA].[E2]>[tA].[E1])
Apr 9 '16 #3
Hi NeoPa,


It does the trick for me when I checked on a small amount of data. It leaeves out the reverse duplicates and the records where both columns wouldhave the same value. the order of the data in the records gets changed with the lower values ending up in the first column but that is just fine making it easier to compare withanother table 'sorted' the same way. I guess it is reliable as long as no two ifferent strings can produce the same value when compared.

As for your much appreciated answer I d like to try it too. But I dont seem to get it to work... I understand [TableName] is the name of my table [Table1] in this case, but do I have to replace the tA tB also by some value, suppose not but... can't get it to work (btw using acces 2010 and yes the data is in seperate fields I just just used '-' to difference between column E1 en E2.

Greetings,
Apr 9 '16 #4
NeoPa
32,556 Expert Mod 16PB
That makes sense. I'm afraid I did it from memory and had forgotten how fussy Access's Jet/ACE can be when handling DELETE queries. My bad.

As a general rule, deleting must be done on a single table. Often this is done by updating something in the record first, with an UPDATE query that allows more complicated SQL, followed by a separate query that deletes the records that have been so flagged. That could be done in this case.

An alternative, if the table has a PK (or any unique index for that matter) defined, then a subquery can be used that returns the records to be deleted in the WHERE clause of a simpler DELETE query. This one I actually tested first and it works fine (After adding a PK [ID] to the table of course) :
Expand|Select|Wrap|Line Numbers
  1. DELETE
  2. FROM   [Table1]
  3. WHERE  ([ID] In(SELECT [tA].[ID]
  4.                 FROM   [Table1] AS [tA]
  5.                        INNER JOIN
  6.                        [Table1] AS [tB]
  7.                   ON   ([tA].[E1]=[tB].[E2])
  8.                  AND   ([tA].[E2]=[tB].[E1])
  9.                 WHERE  ([tA].[E2]<[tA].[E1])))
Apr 10 '16 #5

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

Similar topics

3
by: Wm | last post by:
I have a table of users in mySQL that appears to have a lot of duplicates. What's the best way to look at the userID and email and delete the duplicates? Thanx, Wm
3
by: Alexander Anderson | last post by:
I have a DELETE statement that deletes duplicate data from a table. It takes a long time to execute, so I thought I'd seek advice here. The structure of the table is little funny. The following is...
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...
3
by: EoRaptor013 | last post by:
I'm having trouble figuring out how to delete some _almost_ duplicate records in a look-up table. Here's the table: CREATE TABLE ( (16) NOT NULL , (2) NOT NULL , (20) NULL , (50) NULL...
6
by: Jeff Kish | last post by:
hi. I've seen ways to delete duplicate rows. Can someone give me some sql to do this? I have a table with varchar table_name_start, varchar column_name, varchar table_name_end; it has rows...
6
by: Marlene | last post by:
Hi All I have the following scenario, where I have found all the duplicates in a table, based on an order number and a part number (item).I might have something like this: Order PODate Rec...
1
by: Videotron | last post by:
Thanks to James A. Fortune in this Newsgroups "Creating random letter combinations", I execute the code he proposes and there were 500,000 combinations generated. This is more than we need to give...
1
by: Brian Keanie | last post by:
Used the "find duplicates" wizard to identify approx 500 duplicates in a single table. How do you delete the duplicates without doing it one at a time?
6
by: Parasyke | last post by:
I have a form that uses has a series of about 10 different queries to get the final VIEW query to populate my form. I wrote the below to find the duplicates, which works. I don't want to delete the...
5
by: neelsfer | last post by:
I have a race timing program. In certain races, a team of 2 cyclists may ride together as a team. Both persons will be timed, but only the last person crossing the line's time, must be kept in 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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...
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...

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.