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
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 |
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 |
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 |
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 |
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 |
Answer / dinesh gupta
use distinct commond
distinct(ename) from table name
Is This Answer Correct ? | 0 Yes | 2 No |
Explain what is public role in sql server?
What is database mirroring?
How are the unique and primary key constraints different?
What is use of attributehierarchyenabled? : sql server analysis services, ssas
I am using SQL Server 2005, I have some select and update statements in my query with WHERE clause I want to prevent these queries from SQL injection attacks. What are the steps and precautions to be taken for SQL Injection attacks? Does anybody have suggestions? Thanks in advance,
What stored procedure can you use to display the current processes?
If i have one transaction say mainTransaction, within this mainTransaction i have another two transaction say t1 and t2. Now while execution t1 completes successfully and commit statement fires, but while executing t2 some error occurs and rollback statement fires. What happen to t1, is it rollback or not?
Can we add our custom code in ssis?
What is impersonation? What are the different impersonation options available in ssas? : sql server analysis services, ssas
In performance wise distinct is good or group by is good? eg:select name from emp group by name; select distinct name from emp;
Write a sql query to get zero records from a table having n number of records?
Is sql server difficult to learn?