Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 1st, 2004, 04:44 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
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 .. ?

Reply With Quote
  #2 (permalink)  
Old February 2nd, 2004, 01:15 AM
Authorized User
 
Join Date: Jan 2004
Location: Pune, MAHARASHTRA, India.
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
Reply With Quote
  #3 (permalink)  
Old February 2nd, 2004, 06:02 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
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 ...
Reply With Quote
  #4 (permalink)  
Old February 2nd, 2004, 11:45 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:19 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.