ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
Please give me queries for the following
1. To get the count of duplicate records.
2. A query to delete the duplicate records.
 Question Submitted By :: Srikanth
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Please give me queries for the following 1. To get the count of duplicate records. 2. A query to delete the duplicate records.
Answer
# 1
1. use group by clause with the field on which you want to 
check for duplicates

Ex: select salary,count (*) from employee group by salary 
having count (*)>1

2. Use the below query to delete the duplicate records (not 
the original ones)

SET ROWCOUNT 1 
DELETE yourtable
FROM yourtable a
WHERE (SELECT COUNT(*) FROM yourtable b WHERE b.name1 = 
a.name1 AND b.age1 = a.age1) > 1
WHILE @@rowcount > 0
  DELETE yourtable
  FROM yourtable a
  WHERE (SELECT COUNT(*) FROM yourtable b WHERE b.name1 = 
a.name1 AND b.age1 = a.age1) > 1
SET ROWCOUNT 0
 
Is This Answer Correct ?    4 Yes 0 No
Srikanth
 
  Re: Please give me queries for the following 1. To get the count of duplicate records. 2. A query to delete the duplicate records.
Answer
# 2
For Count Duplicate---
SELECT YourColumn, COUNT(*) TotalCount
FROM YourTable
GROUP BY YourColumn
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC 
For delete Duplicate---
DELETE
FROM MyTable
WHERE ID NOT IN
(
SELECT MAX(ID)
FROM MyTable
GROUP BY DuplicateColumn1, DuplicateColumn2, 
DuplicateColumn2)
 
Is This Answer Correct ?    1 Yes 1 No
Harshad Lakkad (bapunagar Part
 
 
 
  Re: Please give me queries for the following 1. To get the count of duplicate records. 2. A query to delete the duplicate records.
Answer
# 3
1. To get the duplicate records.
Use group by clause to the column on which you want to 
check the duplicates records.
syntax:
select column_name, count(*) from table_name group by 
column_name having count(*) >1

2. To delete the duplicate records.
syntax:
delete from table_name where rowid in (select max(rowid) 
from table_name group by column_name having count(*)>1 )

This will work.
Please let me know in case of any issues.
 
Is This Answer Correct ?    2 Yes 1 No
Meher
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
where do you use Isolations?give me some exmpale?  1
What is an extended stored procedure? Can you instantiate a COM object by using T-SQL? HCL3
What is an extended stored procedure? Can you instantiate a COM object by using T-SQL?  1
What is a transaction and what are ACID properties?  2
Can you give an example of Stored Procedure?  2
What is de-normalization and when do you do it?  3
What are constraints? Explain different types of constraints?  6
How to select Distinct columns from the table, table having 20 columns and i want all coulmns Wipro3
Can Somebody tell me the difference between Clustered & Non- Clustered Index?? Progressive3
CLR Integration ? what is Notification services ? Satyam1
Can we have more than one NULL in a column having unique constraint? 247Customer7
From where can you change the default port?  3
What are mdf,ndf,ldf files and how to see the data in those files? Accenture5
i need some interview questions on sql server developer plz any onee send some links.  1
What is the use of CASCADE CONSTRAINTS?  2
Explain some DBCC commands?  4
What is the difference between DTS and SSIS? Allianz3
What is a table called, if it does not have neither Cluster nor Non-cluster Index?  1
can primery key be a non clustered index?  8
there is a table having two columns no and name and the data is 1 A 2 B 3 C write a query that will result a horizontal output A,B,C vsworx7
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com