UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Removing (mostly) Redundant Rows In A Table    
 
   
Brian63
post Mar 8 2012, 07:40 AM
Post #1

New Member
Posts: 15



Hi all. 1st post on this site.

I have a table which contains data from two source tables.

In some cases I notice I have two rows which have exactly the same population except three fields. In these cases I need to remove one row from the table.

So the field with the key information to use to do this is Batchno

BatchNo Ref

34567 34567
10023 34567

I think I need to write the logic below into a query (still really rubbish at SQL Code)

find both where (appearing on separate rows)

(Row 1) where Batchno = Ref
And
(Row 2) where Batchno not equal to Ref


Then Delete Row Where Batchno IS equal to Ref

Any help would be marvellous

Cheers
B

This post has been edited by Brian63: Mar 8 2012, 07:42 AM
Go to the top of the page
 
+
Bob G
post Mar 8 2012, 07:47 AM
Post #2

UtterAccess VIP
Posts: 8,140
From: CT



(IMG:style_emoticons/default/welcome2UA.gif)

what version of access are you using?

you can also look at the query wizard for finding duplicates within a table. that will at least tell you how many you have to work with
Go to the top of the page
 
+
Brian63
post Mar 8 2012, 07:54 AM
Post #3

New Member
Posts: 15



Hi Bob G

thanks for replying

A2010 x32

The row count for the Dup Wizard reports 16k rows

Many thanks
Kind regards

B
Go to the top of the page
 
+
Bob G
post Mar 8 2012, 08:04 AM
Post #4

UtterAccess VIP
Posts: 8,140
From: CT



i am not running 2010 yet, so we will have to wait for others to jump in
Go to the top of the page
 
+
arnelgp
post Mar 8 2012, 08:07 AM
Post #5

UtterAccess Ruler
Posts: 1,090



on the deletetion part...
delete where both BatchNo and Ref are equal.

docmd.runsql "Delete from yourTable Where BatchNo = Ref;"
Go to the top of the page
 
+
Brian63
post Mar 8 2012, 08:14 AM
Post #6

New Member
Posts: 15



Thanks Bob G
Go to the top of the page
 
+
Brian63
post Mar 8 2012, 08:18 AM
Post #7

New Member
Posts: 15



Hi arnelgp

thanks for replying

Do I open a new query
Add Table
Open SQLView

Copy and paste the code (amended showing myactualtablename you provided into the SQL box

Save and run?

Cheers
Rob
Go to the top of the page
 
+
Bob G
post Mar 8 2012, 08:45 AM
Post #8

UtterAccess VIP
Posts: 8,140
From: CT



before you do anything, make sure to backup your DB just in case
Go to the top of the page
 
+
arnelgp
post Mar 8 2012, 09:05 AM
Post #9

UtterAccess Ruler
Posts: 1,090



As Bob said, make backup first, there is no undelete process when you run the code.
Yes you replace yourTableName with the table with which you will delete records.
Open the the VBA Editor, I dont have my MS 2010 right now, so just press Alt+F11 to invoke it.
If the immediate window is not displayed, goto the View immediate window or Ctrl+G.
Start typing(in immediate window, usually at the bottom right of screen): docmd.RunSQL "Delete from yourTableName Where BatchNo = Ref;"

This post has been edited by arnelgp: Mar 8 2012, 09:07 AM
Go to the top of the page
 
+
Brian63
post Mar 8 2012, 09:32 AM
Post #10

New Member
Posts: 15



Hi,

Back up made.

I have typed in the (location amended) code into the Immediate Window.

Sorry about this, but I have never used the VBA Editor before.

What do I do now?

As before
Many thanks


B
Go to the top of the page
 
+
Brian63
post Mar 8 2012, 11:09 AM
Post #11

New Member
Posts: 15



Hi,

I used the logic in the SQL code, provided by arnelgp, to create a query. Tested the query as Select.

I then changed the query type to Delete and ran it.

Job done.

Thank for your valuable input.

B.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 25th May 2013 - 02:49 PM