Select Ename
from emp
group by Ename
having count(*) > 1
select sal,Ename,count(*)
from emp
group by sal,Ename
having count(*) > 1
select sal,Ename
from emp
group by sal,Ename
having count(*) > 1
Return all pairs of city IDs that have the same city name
select * from emp
select c1.empno, c2.empno, c1.Ename
from emp c1, emp c2
where c1.empno ename = c2.Ename
Delete Duplicate Records – Rows
Example:1
DELETE
FROM emp
WHERE Empno NOT IN (SELECT MAX(Empno)FROM empGROUP BY ename)
Example:2
DELETE
FROM emp
WHERE EXISTS (
SELECT * FROM emp AS b
WHERE
b.[ename] = emp.[ename]
--AND b.[col2] = emp.[col2]
--AND b.[col3] = emp.[col3]
GROUP BY b.[ename]--, b.[col2], b.[col3]
HAVING emp.[Empno] > MIN(b.[Empno]
)
Subscribe to:
Post Comments (Atom)
2nd row of duplicate record
ReplyDeleteselect col from (select ROW_NUMBER() over (order by col asc) as 'rowNum', col from [table] ) with RowNum where rowNum = 2
2nd row of duplicate record(verified by SQL from w3school.com)
ReplyDeleteselect min(quantity) from OrderDetails where quantity in
(select TOP 2 (quantity) from OrderDetails order by quantity desc)