Wrox Programmer Forums
|
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2008, 01:19 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default Deleting Duplicate Records

Here’s an odd question.

Given a table with 2 col.s, DOCN & PROJ which has some duplicate rec.s, how can I delete a specific row, using SQL?

The issue that brought me to this question is a desire to delete all the duplicates, without deleting the representative record.

If I have
Code:
   12345  NULL
   12345  NULL  <——<<< Dupe
   12345  NULL  <——<<< Dupe
   23456  NULL
   34567  NULL
   34567  NULL  <——<<< Dupe
   I want to end up with
Code:
   12345  NULL
Code:
   23456  NULL
   34567  NULL
   Note that there is no ID-type column.

(Of course
Code:
DELETE FROM <table>
WHERE  DOCN = '12345'
would delete all the records having DOCN = '12345'. I want to leave one behind...)
 
Old February 22nd, 2008, 01:30 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I had the same issue a while back and found this article useful:

http://www.kodyaz.com/articles/delet...n-a-table.aspx

For the record, I hate cursors but this is a situation where I don't mind using them.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
duplicate records vanitha SQL Server 2000 4 June 2nd, 2007 04:35 PM
duplicate records vanitha Reporting Services 2 May 31st, 2007 01:54 AM
Deleting duplicate records ninel SQL Server 2000 3 June 14th, 2006 02:12 PM
Duplicate Records mrookey Dreamweaver (all versions) 1 April 15th, 2005 11:23 AM
deleting only 1 duplicate entry qwjunk Classic ASP Databases 3 February 2nd, 2004 11:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.