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   SiteMap shows list of All Categories in this site.
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
Delete duplicate rows from a table without primary key by 
using a single query
Table Employee
empname salary
A         200
B         300
A         200
C         400
D         500
D         500

Output should be

A         200
B         300
C         400
D         500

 Question Submitted By :: Ayanb1302@yahoo.com
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Delete duplicate rows from a table without primary key by using a single query Table Employee empname salary A 200 B 300 A 200 C 400 D 500 D 500 Output should be A 200 B 300 C 400 D 500
Answer
# 1
Execute the following query for each duplicate value.

1.Delete duplicate of empname='A'

delete top(select count(*)-1 from employee where
empname='A') from employee where empname='A'

2.Delete duplicate of empname='D'

delete top(select count(*)-1 from employee where
empname='D') from employee where empname='D'
 
Is This Answer Correct ?    1 Yes 1 No
Sumathy
 
  Re: Delete duplicate rows from a table without primary key by using a single query Table Employee empname salary A 200 B 300 A 200 C 400 D 500 D 500 Output should be A 200 B 300 C 400 D 500
Answer
# 2
declare  myCursor cursor for
select empid
				from employee 
				group by empid
				having count(*) > 1

declare @EmpId int


OPEN myCursor;
		FETCH NEXT FROM myCursor INTO @EmpId
		WHILE @@FETCH_STATUS = 0
		BEGIN

		delete top(select count(*)-1 from employee where
		empid=@EmpId) from employee where empid=@EmpId

FETCH NEXT FROM myCursor INTO @EmpId
		END
close myCursor  

deallocate myCursor
 
Is This Answer Correct ?    1 Yes 0 No
Swati Tripathi
 
 
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
can you any body tell me why are go for the rebuild the master database.what is the reason?  1
how to find number of columns in a table in sql server 2000 and 2005 also Virtusa7
When do you use SQL Profiler?  2
What are the advantages of using stored procedures? Please don't simply say compilation time will be saved as they are already complied. Please specify some other advantages. 247Customer3
What is the Query of getting last 10 transaction Reports (like insert, update, Delete Data from Tabele) ? Wipro4
What is the system function to get the current user's user id? HCL1
The Difference between 'Count' and 'Count(*)'  12
How to write query to Delete the records in child table and corresponding records in parent table Semantic-Space8
How can i change the column name. HCL7
How to get the count of distinct records. Please give me the query? Value-Labs5
I have student marks in a student table. I need second highest mark .Then what will the query for this? Wipro23
one table has four field id,name,design,salary. i have to find maximum salary .  6
Can we use Truncate command on a table which is referenced by FOREIGN KEY?  2
How the data stores in a page?  1
What are user defined datatypes and when you should go for them?  1
What is the advantage of specifying WITH GRANT OPTION in the GRANT command?  2
How to restart SQL Server in single user mode? How to start SQL Server in minimal configuration mode? HCL2
UPDATE statement can on a single table or on the multiple table? iGate5
How will u get 5 years back record?  4
How can you get @@error and @@rowcount at the same time?  5
 
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