How to Delete Duplicate Records in Oracle

Method 1 of 4:

Identifying your Duplicate

  1. How to Delete Duplicate Records in Oracle Picture 1
    Identify the duplicate. In this case, identify the example duplicate, "Alan." Make sure that the records you are trying to delete are actually duplicates by entering the SQL below.
  2. How to Delete Duplicate Records in Oracle Picture 2
    Identifying from a column named "Names." In the instance of a column named "Names," you would replace "column_name" with Names.
  3. How to Delete Duplicate Records in Oracle Picture 3
    Identifying from other columns. If you were trying to identify the duplicate by a different column, for example the age of Alan rather than his name, you would enter "Ages" in the place of "column_name" and so on.
    select column_name, count(column_name) from table group by column_name having count (column_name) > 1; 
Method 2 of 4:

Deleting a Single Duplicate

  1. How to Delete Duplicate Records in Oracle Picture 4
    Select "name from names." After "SQL," which stands for Standard Query Language, enter "select name from names."
  2. How to Delete Duplicate Records in Oracle Picture 5
    Delete all of the rows with the duplicate name. After "SQL," enter "delete from names where name='Alan';." Note that capitalization is important here, so this will delete all of the rows named "Alan." After "SQL," enter "commit."[1]
  3. How to Delete Duplicate Records in Oracle Picture 6
    Renter the row without a duplicate. Now that you have deleted all rows with the example name "Alan," you can insert one back by entering "insert into name values ('Alan');." After "SQL," enter "commit" to create your new row.
  4. How to Delete Duplicate Records in Oracle Picture 7
    See your new list. Once you have completed the above steps, you can check to make sure you no longer have duplicate records by entering "select * from names."
    SQL > select name from names; NAME ------------------------------ Alan Carrie Tom Alan rows selected. SQL > delete from names where name='Alan'; rows deleted. SQL > commit; Commit complete. SQL > insert into names values ('Alan'); row created. SQL > commit; Commit complete. SQL > select * from names; NAME ------------------------------ Alan Carrie Tom rows selected. 
Method 3 of 4:

Deleting Multiple Duplicates

  1. How to Delete Duplicate Records in Oracle Picture 8
    Select the RowID you want to delete. After "SQL," enter "select rowid, name from names;."
  2. How to Delete Duplicate Records in Oracle Picture 9
    Delete the duplicate. After "SQL," enter "delete from names a where rowid > (select min(rowid) from names b where b.name=a.name);" to delete duplicate records.[2]
  3. How to Delete Duplicate Records in Oracle Picture 10
    Check for duplicates. After you have completed the above, commands check to see if you still have duplicate records by entering "select rowid,name from names;" and then "commit."
    SQL > select rowid,name from names; ROWID NAME ------------------ ------------------------------ AABJnsAAGAAAdfOAAA Alan AABJnsAAGAAAdfOAAB Alan AABJnsAAGAAAdfOAAC Carrie AABJnsAAGAAAdfOAAD Tom AABJnsAAGAAAdfOAAF Alan rows selected. SQL > delete from names a where rowid > (select min(rowid) from names b where b.name=a.name ); rows deleted. SQL > select rowid,name from names; ROWID NAME ------------------ ------------------------------ AABJnsAAGAAAdfOAAA Alan AABJnsAAGAAAdfOAAC Carrie AABJnsAAGAAAdfOAAD Tom rows selected. SQL > commit; Commit complete. 
Method 4 of 4:

Deleting Rows with Columns

  1. How to Delete Duplicate Records in Oracle Picture 11
    Select your rows. After "SQL," enter "select * from names;" to see your rows.
  2. How to Delete Duplicate Records in Oracle Picture 12
    Delete duplicate rows by identifying their column. After "SQL'" enter "delete from names a where rowid > (select min(rowid) from names b where b.name=a.name and b.age=a.age);" to delete the duplicate records.[3]
  3. How to Delete Duplicate Records in Oracle Picture 13
    Check for duplicates. Once you have completed the above steps, enter "select * from names;" and then "commit" in order to check that you have deleted the duplicate records successfully.
    SQL > select * from names; NAME AGE ------------------------------ ---------- Alan 50 Carrie 51 Tom 52 Alan 50 rows selected. SQL > delete from names a where rowid > (select min(rowid) from names b where b.name=a.name and b.age=a.age ); row deleted. SQL > select * from names; NAME AGE ------------------------------ ---------- Alan 50 Carrie 51 Tom 52 rows selected. SQL > commit; Commit complete. 
4.3 ★ | 12 Vote

May be interested

  • How to Reset SA Password in Sql ServerPhoto of How to Reset SA Password in Sql Server
    this wikihow teaches you how to reset a forgotten system administrator (sa) password in microsoft's sql server. you can do this by logging in with windows authentication, using command prompt, or using single-user mode. understand how this...
  • How to Learn Data EntryPhoto of How to Learn Data Entry
    data entry is simply the transcription of data from one form into another. the majority of businesses require data entry, such as entering sales figures into a spreadsheet, transcribing notes from a meeting, or integrating databases. if...
  • How to Create a Database from an Excel SpreadsheetPhoto of How to Create a Database from an Excel Spreadsheet
    this wikihow teaches you how to create a database using data from a microsoft excel spreadsheet by importing the data directly into access, which is microsoft's database management software, or by exporting the excel data into a format...
  • How to Keep and Control Records Using Microsoft AccessPhoto of How to Keep and Control Records Using Microsoft Access
    keeping records on a computer allows you easy, on-demand access to all your records. there are many computerized record-keeping programs out there (usually called database applications), but if you have a computer running windows,...
  • How to Disable Microsoft Security EssentialsPhoto of How to Disable Microsoft Security Essentials
    many people today who use windows also use microsoft security essentials (mse). mse is a built-in protection on your computer against viruses, spyware, and other malicious software. there are times that users might want to to temporarily...
  • How to Link Tables in AccessPhoto of How to Link Tables in Access
    microsoft access allows tables and databases to connect with each other. this capability can increase your efficiency and easily spread information that is required for multiple departments or reports. you can make changes in the original...