sql - logic behind deletion of duplicate rows? -
what logic behind deletion of duplicate rows? got know query used delete duplicate rows.
delete tvsemp e rowid>(select min(rowid) tvsemp m e.ename=m.ename);
here when divided subquery i.e first select min(m.rowid) tvsemp e, tvsemp m e.ename=m.ename;
result rowid
min(m.rowid) ___________________ aaaeduaabaaakiqaap
then outer query select ename tvsemp emp rowid>'aaaeduaabaaakiqaap'
getting n-1 results(except 1 eliminated using '>' sin)
my doubt if 2 combined getting exact table without duplicate why this?
are asking if first query work?
delete tvsemp e rowid>(select min(rowid) tvsemp m e.ename=m.ename);
the answer "yes".
as how works, subquery correlated subquery, means references outer query. oracle executes subquery each row of tvsemp e
, , e.ename = m.ename
in subquery limits subquery's results rows ename
equals ename
in outer query's current row.
getting n - 1
results want: if there 4 rows name chay
, want delete 3 of them.
put way, if there 4 rows name chay
, 1 of them have minimum rowid
value. rowid
other 3 higher minimum, delete
query delete them.
i hope makes sense. there's more information subqueries (including correlated subqueries) here.
Comments
Post a Comment