write a query to delete similar records in same table

Answers were Sorted based on User's Feedback



write a query to delete similar records in same table..

Answer / sivadasan

I think simply we can do like the following..

1. First we have to transfer all data from a table to
temporary table

create table Temp_table as select * from original_table;

2. Delete all record from Original Table....

delete original_table;

3. Now we can write a query by using INSERT and UNION

If any issue let me know....

insert into original_table (select * from temp_table
UNION select * from UNION )

Is This Answer Correct ?    0 Yes 3 No

write a query to delete similar records in same table..

Answer / umadevi

--deletes records within table without changing table name
delete from temp t1 where rowid<(select max(rowid) from temp
t2 where t1.empno=t2.empno) order by empno;

or
--create new table n insert records.
create table t1 as select distinct * from temp;

or
(truncate table)
truncate table t1;
insert into t1 select distinct * from temp;

Is This Answer Correct ?    1 Yes 5 No

write a query to delete similar records in same table..

Answer / swapna

One way is to rename the original table to something else,
and copy the unique records into the original table.

rename 'Table2', 'Table1'

select distinct * into Table2 from Table1

drop table1

Is This Answer Correct ?    5 Yes 13 No

Post New Answer

More SQL PLSQL Interview Questions

What are the different types of database management systems?

0 Answers  


Is primary key always clustered index?

0 Answers  


What is the maximum number of rows in sql table?

0 Answers  


I Defined SP1, Sp2 (sp=StoreProcedures)In Package Specification but I Implemented Sp1, sp2, sp3, sp4, sp5 then What type of Error You will find????

3 Answers   Infosys,


What are the advantages of pl sql over sql?

0 Answers  






What are the usages of sql?

0 Answers  


Write the command to remove all players named sachin from the players table.

0 Answers  


How insert into statements in sql?

0 Answers  


in sql table following column r there i want find 1st paid ,2nd paid,3rd paid date for same |service_type|date |vehicle_no| |------------|------|_---------| |paid |23 jan|MH12H2007 | | | | | |paid |26 feb|MH12H2007 | | | | | | | | | |paid |28 mar|MH12H2007 | i want o/p like below vehicle no| 1st paid date | 2nd paid date|3rd paid |latest paid date| pls help me out

4 Answers  


What is pl/sql and what is it used for?

4 Answers  


What is the criteria while applying index to any column on any table.

1 Answers   Infogain,


Why is sql important?

0 Answers  


Categories