Remove rows with dublicate field values

Almeding

New Member
Joined
Aug 1, 2017
Messages
2
Hi,

I have two tables: one with all items from a ERP-system (2), and one with manual correction to the items lists product hierachy (1). The manual corrections (1) can hold items which also will be found in the item list table (2).

The two tables are joined in an UNION query. My problem is that in case the item is found in both tables I only want to keep records from table (1).

So this table:

MinOfSYSFirstOfHierarchy 1FirstOfHierarchy 2FirstOfHierarchy 3FirstOfCOMPANYUNITSCOSTEAN
1ABCDDDKKKAAA646,04553 6.310.183.055.272
1ABCDDDKKKAAA649,163 6.310.183.055.289
1ABCDDDKKKAAA650,7706 6.310.183.055.296
1ABCDDDKKKAAA653,9078 6.310.183.055.302
2ABCDDDKKKBBB646,04553 6.310.183.055.272
2ABCDDDKKKBBB649,16308 6.310.183.055.289
2ABCDDDKKKBBB650,77057 6.310.183.055.296
2ABCDDDKKKBBB653,90778 6.310.183.055.302
2ABCDDDKKKBBB961002,82563 6.310.183.256.013
2ABCDDDKKKBBB96968,89833 6.310.183.256.006

<colgroup><col width="67" style="width:50pt"> <col width="157" style="width:118pt" span="4"> <col width="44" style="width:33pt"> <col width="74" style="width:56pt"> <col width="134" style="width:101pt"> </colgroup><tbody>
</tbody>


Should end up like this:

MinOfSYSFirstOfHierarchy 1FirstOfHierarchy 2FirstOfHierarchy 3FirstOfCOMPANYUNITSCOSTEAN
1ABCDDDKKKAAA646,04553 6.310.183.055.272
1ABCDDDKKKAAA649,163 6.310.183.055.289
1ABCDDDKKKAAA650,7706 6.310.183.055.296
1ABCDDDKKKAAA653,9078 6.310.183.055.302
2ABCDDDKKKBBB961002,82563 6.310.183.256.013
2ABCDDDKKKBBB96968,89833 6.310.183.256.006

<colgroup><col width="67" style="width:50pt"> <col width="157" style="width:118pt" span="4"> <col width="44" style="width:33pt"> <col width="74" style="width:56pt"> <col width="134" style="width:101pt"> </colgroup><tbody>
</tbody>


I have tried MIN, FIRST etc, but then I get the wrong hierachy

Any help will be much appreciated - thanks

brgds
a novice
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Forgot - the EAN-code must be unique, so it should return this (table (1)):

1ABCDDDKKKAAA646,045536.310.183.055.272

<tbody>
</tbody>


and remove this (from table (2))
2ABCDDDKKKBBB646,045536.310.183.055.272

<tbody>
</tbody>
 
Upvote 0
If you do a group query and use the union query as the source... maybe something like:

Code:
SELECT First(MinOfSys) AS 1stSys, First([FirstOfHierarchy 1]) AS [1stHierarchy 1], First([FirstOfHierarchy 2]) AS [1stOfHierarchy 2], First([FirstOfHierarchy 3]) AS [1stOfHierarchy 3], First(FirstOfCOMPANY) AS 1stCOMPANY, First(UNITS) AS 1stUNITS, First(COST) AS 1stCOST, EAN

FROM (Select * from [COLOR=#FF0000]table1[/COLOR] UNION ALL select * from[COLOR=#FF0000] table2[/COLOR])

GROUP BY EAN;
 
Upvote 0
Wondering if a subquery would work along the lines of
Code:
DELETE Table1.[MinOfSys] FROM Table1 WHERE 
(((Table1.[MinOfSys] = (SELECT [MinOfSys] AS Tmp FROM [Table1] As Dupe 
WHERE (Dupe.[EAN] = Table1.[EAN]))));
Don't try these on anything but copies of your data!
 
Upvote 0

Forum statistics

Threads
1,215,217
Messages
6,123,670
Members
449,115
Latest member
punka6

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top