Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP 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 1st, 2004, 04:44 AM
Authorized User
 
Join Date: Jan 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default deleting only 1 duplicate entry

ive two duplicate entries in my db .. now i want to delete only one of them preferably the second occurance only .. how do i do that using sql ?

when i use the normal sql ie. DELETE .. WHERE FileID=required ID

it deletes both occurences .. how do i fix this .. ?

 
Old February 2nd, 2004, 01:15 AM
Authorized User
 
Join Date: Jan 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ankur_vachhani
Default

use this sql query to delete only one duplicate record


    delete from your_table where rowid in
    ( select min(rowid) from your_table where FileID = your_requiredID)


        HTH
 
Old February 2nd, 2004, 06:02 AM
Authorized User
 
Join Date: Jan 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it deletes both the occurences .. im not sure if im applying the rowid part correctly ..

this is what is used..

delete from table where FILE_NO in ( select min(FILE_NO) from patient where FILE_NO = 89523)

i want the second occurence to be deleted ...
 
Old February 2nd, 2004, 11:45 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

By "rowid" ankur was suggesting that you have something in your table that uniquely identifies each row (like an identity column). (Of course, if this were the case, then technically your wouldn't have duplicate rows.)

Is this a process you need to run regularly? Or is this something you are doing just to clean up some data? If this is a regular occurance, you should re-consider your table design. You shouldn't allow the insertion of duplicate data.

In order to only delete one row, you need some means of uniquely identifying each row so you have some criteria to separate duplicates. If you have that, then you could use the "min(rowid)" suggestion.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for Duplicate Records in Data Entry Form roznix Access VBA 5 June 7th, 2012 08:53 AM
Checking for duplicate entry in Database sharon5469 ASP.NET 1.0 and 1.1 Basics 1 November 18th, 2007 06:08 PM
Duplicate database entry redirection error page EmWebs Dreamweaver (all versions) 3 December 29th, 2006 10:17 AM
Duplicate database entry redirection error page EmWebs Access ASP 0 December 27th, 2006 12:54 PM
avoid duplicate entry of records mikersantiago Classic ASP Basics 4 February 10th, 2005 09:14 PM





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