Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

DBMS 

How to delete only one row from duplicate rows in Oracle SQL?

I have the following table:

Name Address
VCR Mumbai
VCR Mumbai

Now there are 2 rows and they are duplicate.

How can I delete the second row or first row so that only one row is present?

I tried:

Delete from stud where name = 'VCR' limit 1;

But it is giving me error. Please help.
"It is a simple logic truth that, short of mass emigration into space, with rockets taking off at the rate of several million per second, uncontrolled birth rates are bound to lead to horribly increased death rates."

- Richard Dawkins (The Selfish Gene)
Don't you have a primary key defined?
PHP Code

<?php 
delete from yourtable
where rowid not in
(select min(rowid)
from yourtable
group by name
, address); 
@SirRootALot No bro. Otherwise it would have been super simple.

@stugz Thanks. I'll check it out and edit the post.

EDIT: What is rowid in your code?
"It is a simple logic truth that, short of mass emigration into space, with rockets taking off at the rate of several million per second, uncontrolled birth rates are bound to lead to horribly increased death rates."

- Richard Dawkins (The Selfish Gene)
rowid is a pseudo-column which can be used to find the physical address of a row.
why not just create a new table using a select statement on the original but with a distinct action.

then delete original and rename copy back to original name.
(May 1, 2015 01:04 PM)martin_w35 Wrote:  why not just create a new table using a select statement on the original but with a distinct action.

then delete original and rename copy back to original name.

Because production, bad downtime, bad habbit.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by AnGrY BoMay 17, 2018 01:19 PM 4 133 May 17, 2018 01:19 PM
Last Post: AnGrY Bo
by RenovatumMar 2, 2018 01:48 PM 3 168 Mar 2, 2018 01:48 PM
Last Post: Renovatum
[Help] by multiscreenMar 18, 2017 05:31 AM 0 106 Mar 18, 2017 05:31 AM
Last Post: multiscreen