Suppose we have table Name as “Dummy”
Query:- Select * from Dummy;
O/P:- ID | Name
----------
1 | A
1 | B
1 | C
2 | D
Condition 1:- When we need to delete the record
from Dummy table where id=1 and found in first priority i.e updated record or
we can say the latest record and delete all other records for id=1
Query:-Delete from Dummy where rowid not
in (SELECT max(rowid) from Dummy group by id);
O/P:- ID | Name
---------------
1 | C
2 | D
Condition 2:-When we need to delete the record
from Dummy table where id=1, Then left the only first record that we have inserted
initially and delete all other records for id=1
Query:- Delete from Dummy where rowid not in (SELECT
min(rowid) from Dummy group by id);
O/P:-
ID | Name
---------------
1 | A
2 | D
Note:- ROWID is basically a pseudocolumn that returns the
address of the row, It contains the information of object like the data block
in the datafile in which the row resides or the position of the rows etc.
No comments:
Post a Comment