Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


in tabase table having a column in it empname field is
there which having 5 duplicate values is there i want
deleted all the duplicates i want showing only one name
only.

Answers were Sorted based on User's Feedback



in tabase table having a column in it empname field is there which having 5 duplicate values is th..

Answer / karna

delete from emp where empid not in(select max(empid) from
emp group by empname having count(*)>=1)

Is This Answer Correct ?    2 Yes 0 No

in tabase table having a column in it empname field is there which having 5 duplicate values is th..

Answer / jiri

WITH DUPLICATE(EmpName, RowNumber)
AS
(SELECT EmpName,ROW_NUMBER() OVER (PARTITION BY EmpName
order by EmpName) AS RowNumber
FROM Employee)

DELETE FROM DUPLICATE WHERE RowNumber > 1

------------------------------------------------------------
Using CTE (Common Table Expressions) and ROW_NUMBER as
ranking fucntion


Jiri JANECEK
MSE, MBA, MCSD.NET

Is This Answer Correct ?    1 Yes 0 No

in tabase table having a column in it empname field is there which having 5 duplicate values is th..

Answer / ambarish

we can use cursor.

Is This Answer Correct ?    0 Yes 0 No

in tabase table having a column in it empname field is there which having 5 duplicate values is th..

Answer / venkat

Hope this methodology would help you better

1.Create a temp table
2.Select duplicated row's empid,empname into the temp table.
3.Create a cursor by selecting values from temp table.
4.Keep either min or max(empid) from original table and
delete the rest of the duplicated rows.

Is This Answer Correct ?    0 Yes 0 No

in tabase table having a column in it empname field is there which having 5 duplicate values is th..

Answer / kumar

Table structure :-

empid empname
1 bala
2 bala
3 bala
4 bala
5 arun
6 arun
7 arun
8 ram
9 ram

Delete from employee where empid
not in (Select min(empid) from employee group by emp
having count(empid)>1)

By
Kumar

Is This Answer Correct ?    1 Yes 1 No

in tabase table having a column in it empname field is there which having 5 duplicate values is th..

Answer / dinesh gupta

Kumar your query do not solve the purpose accurately.

It should be as

Delete from employee where empid
not in (Select min(empid) from employee group by empname
having count(empname)>=1)

Is This Answer Correct ?    1 Yes 1 No

in tabase table having a column in it empname field is there which having 5 duplicate values is th..

Answer / dinesh gupta

use distinct commond

distinct(ename) from table name

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More SQL Server Interview Questions

How to create a ddl trigger using "create trigger" statements?

0 Answers  


What is the standby server?

0 Answers  


What is blocking in SQL Server? If this situation occurs how to troubleshoot this issue

2 Answers   IBM,


How do I view views in sql server?

0 Answers  


user defined datatypes

1 Answers   Wipro,


Name three version of sql server 2000 and also their differences?

1 Answers  


what is an extended stored procedure? Can you instantiate a com object by using t-sql? : Sql server database administration

0 Answers  


HOW TO RENAME A COLUMN NAME

3 Answers  


what is unique and xaml nonclustered index

0 Answers  


What is the difference between push and pull subscription? : sql server replication

0 Answers  


Is trigger fired implicitely?

2 Answers  


Explain the dirty pages?

0 Answers  


Categories