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
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
 
How can you get @@error and @@rowcount at the same time?  5
What do u mean by orphan users, how will u list them in the DB IBM2
what is the out put of below queries? a. select * from Emp where null = null; b. select * from Emp where 1=1; Patni9
What is de-normalization and when do you do it?  3
How to delete an attribute from the emp table  3
WHICH INDEX IS FAST CLUSTER AND NON CLUSTER INDEX L&T2
What is the appropriate number of test cases that you can write on a database? Microsoft1
How are SQL Server databases physically stored under Windows 2000?  1
How to tune a stored procedure?  5
1.How to check the backup file details if we do not have access to that folder 2.how to check the backup file size without connecting to the folder IBM1
Can we call SP inside a query? Wipro4
what is hash table Teledata2
What is normalization and its forms? Challenger-Financial3
How do I list the available tables in a database I'm querying?  3
how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,... ADP5
What are the different ways of moving data/databases between servers and databases in SQL Server? HCL2
How many max. conditions can b written under the WHERE clause? Like select * from [tabnam] WHERE (cond1...or..cond2....or...cond3...and.....so on.....??? (upto how much extent))????? SAP-Labs2
What are cursors?  8
What is cursor ? And what is difference between Trigger ? HCL1
I have to display ten columns values from diffrent ten tables. how many joins are require? HCL8
 
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