Click here to Skip to main content
15,924,402 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi friends,
In my database unfortunately doubled one field.
Eg: In database ,I want original one data like "Enquiryid=123 and Coursename=nnn"
But now in my database every data is doubled;
Eg: "Enquiryid=123 and Courcename=nnn"
"Enquiryid=123 and Courcename=nnn"
I want to delete repeated 'enquiry_id'from my database but there should remaine original of the repeated 'enquiry_id' and its corresponding rows.......
do u get me????????then give me the sql query for this problem
Posted
Updated 21-Sep-11 1:24am
v3

Hi.. Try below

To retain (eleminate) duplicate:

SELECT Enquiryid,Coursename,ROW_NUMBER() OVER(ORDER BY SlNo ) AS 'Row Number',*
FROM employee
GROUP BY Enquiryid,Coursename
Having Count(*)>1


To Delete duplicate:

;with TBLCTE(Enquiryid,Coursename)
AS
(
select
Enquiryid,Coursename,
Ranking = DENSE_RANK() over (PARTITION BY Enquiryid,Coursename order by newID())
from Employee
)
delete from TBLCTE where Ranking > 1

select * from Employee
 
Share this answer
 
Try this.
SQL
DELETE TOP(1) FROM tablename WHERE Enquiryid = 123 AND Coursename = 'nnn'"
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900