View previous topic :: View next topic
|
Author |
Message |
ganna_f16
New User
Joined: 07 Mar 2005 Posts: 17 Location: India
|
|
|
|
Hi,
I am having a table with more duplicates(for example Empno). If I run the query like
DELETE FROM EMP-TABLE where EMP-NO='007';
This is going to delete all the rows which satisfies the condition.
But my requirement is to delete only the first record i.e if the condition satisfies for three records the it should delete only first record and remaining two records should be in table.
Thanks in advance.
Regards,
Ganna. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
use a cursor for update. but which is the first? |
|
Back to top |
|
|
ruodeer
New User
Joined: 06 Jul 2007 Posts: 58 Location: home
|
|
|
|
yep, a method is that using a cursor to save the first coming one , then deleting the remaining..... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Reading the responses to your question shows that different people have a different understanding of your requirement.
To continue with your example (3 rows containing emp-no=007), do you really want to delete the first one encountered and keep the other 2? Seems like this would result in the table still having duplicates.
Should there not be some ordering criteria (i.e. keep the oldest or keep the newest)? Deleting an arbitrary row that happens to meet the 007 criteria seems to be less than specific.
If you more clearly define your requirement, you may get better replies. |
|
Back to top |
|
|
|