Results 1 to 4 of 4

Thread: Remove duplicate entries [RESOLVED]

  1. #1
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 02
    Location
    Karachi
    Posts
    1,300

    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 07:44 AM.
    The secret of creativity is knowing how to hide your sources...

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 05
    Location
    Philippines
    Posts
    10,226

    Re: Remove duplicate entries

    You could try using a temporary table and do something like the ff...

    VB Code:
    1. INSERT INTO a ( MasterBL, RefNum, Vessel, Country, Shipper, ArrivalDate, Port, Reg, RegYear, Carrier, ExcRate, CargoLocation, [Container], ShipmentMode, Status )
    2. 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
    3. FROM ImpMBL;

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 00
    Location
    Excel Hell!
    Posts
    4,895

    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.

    BOFH Now, BOFH Past, Information on duplicates

    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...

  4. #4
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 02
    Location
    Karachi
    Posts
    1,300

    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);
    The secret of creativity is knowing how to hide your sources...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •