|
-
Jan 10th, 2006, 03:04 AM
#1
Thread Starter
Frenzied Member
Remove duplicate entries [RESOLVED]
Hello everybody,
In my table, I have a field StockName. This field contains duplicate data as a result of import. I need to remove all the records that are duplicate with StockName.
Say, if StockName field has a value "somevalue" and this value is five times, then four values should be removed and one should left. same the case with any value in the StockName field. Table contains thousands of records.
Any ideas ??
Thanks.
Last edited by usamaalam; Jan 10th, 2006 at 08:44 AM.
-
Jan 10th, 2006, 03:20 AM
#2
Re: Remove duplicate entries
You could try using a temporary table and do something like the ff...
VB Code:
INSERT INTO a ( MasterBL, RefNum, Vessel, Country, Shipper, ArrivalDate, Port, Reg, RegYear, Carrier, ExcRate, CargoLocation, [Container], ShipmentMode, Status )
SELECT DISTINCT ImpMBL.MasterBL, ImpMBL.RefNum, ImpMBL.Vessel, ImpMBL.Country, ImpMBL.Shipper, ImpMBL.ArrivalDate, ImpMBL.Port, ImpMBL.Reg, ImpMBL.RegYear, ImpMBL.Carrier, ImpMBL.ExcRate, ImpMBL.CargoLocation, ImpMBL.Container, ImpMBL.ShipmentMode, ImpMBL.Status
FROM ImpMBL;
-
Jan 10th, 2006, 05:44 AM
#3
Re: Remove duplicate entries
Check out the function First (it is this in Access and Sql server I think) or the equivalent.
Should return the first record with that value and you can use that to export to another table (use a make table query or something) depending on the db you are using.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jan 10th, 2006, 06:40 AM
#4
Thread Starter
Frenzied Member
Re: Remove duplicate entries
Thanks all. Issue has been resolved using this query.
Code:
DELETE
FROM Onyak_Sigmapro_Stock
WHERE Onyak_Sigmapro_Stock.StockId IN
(SELECT Stock.StockId
FROM Onyak_Sigmapro_Stock AS Stock
WHERE Exists (SELECT StockName,Count(StockId)
FROM Onyak_Sigmapro_Stock
WHERE Onyak_Sigmapro_Stock.StockName = Stock.StockName
GROUP BY Onyak_Sigmapro_Stock.StockName
HAVING Count(Onyak_Sigmapro_Stock.StockId) > 1))
AND Onyak_Sigmapro_Stock.StockId NOT IN
(SELECT Min(StockId)
FROM Onyak_Sigmapro_Stock AS Stock
WHERE Exists (SELECT StockName, Count(StockId)
FROM Onyak_Sigmapro_Stock
WHERE Onyak_Sigmapro_Stock.StockName = Stock.StockName
GROUP BY Onyak_Sigmapro_Stock.StockName
HAVING Count(Onyak_Sigmapro_Stock.StockId) > 1)
GROUP BY StockName);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|