Results 1 to 4 of 4

Thread: Remove duplicate entries [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    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.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    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;
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    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

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    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
  •  



Click Here to Expand Forum to Full Width