SQL Tips: How to detect duplicate rows in table
2013-09-06 08:19
549 查看
For example:
-- O: Original table
-- D: Duplicate records table
select O.*, D.RecCount
from tblFunctionality O
inner join
(
select FunctionalityName, IsGroup, ParentId, COUNT(*) AS RecCount
from tblFunctionality
group by FunctionalityName, IsGroup, ParentId
having COUNT(*) > 1
) D
on
O.FunctionalityName = D.FunctionalityName AND
O.IsGroup = D.IsGroup AND
O.ParentId = D.ParentId
order by O.FunctionalityName, O.IsGroup, O.ParentId;
-- O: Original table
-- D: Duplicate records table
select O.*, D.RecCount
from tblFunctionality O
inner join
(
select FunctionalityName, IsGroup, ParentId, COUNT(*) AS RecCount
from tblFunctionality
group by FunctionalityName, IsGroup, ParentId
having COUNT(*) > 1
) D
on
O.FunctionalityName = D.FunctionalityName AND
O.IsGroup = D.IsGroup AND
O.ParentId = D.ParentId
order by O.FunctionalityName, O.IsGroup, O.ParentId;
相关文章推荐
- How to delete duplicate rows without children in sql server
- How-to find the SQL that using lots of temp tablespace in Oracle
- 转:How to submit rows of a repeating table in InfoPath to a web service? 如何将重复表中的记录传给Web Service ?
- Fastest Way to Update Rows in a Large Table in SQL Server
- An example to show how to make Tree structure data table in SQL server
- 转:How to submit the rows of a repeating table in InfoPath to a SharePoint list
- How to Implement an Automatic Sliding Window in a Partitioned Table on SQL Server 2005
- How to delete duplicate rows with SQL
- T-SQL Tips: How to raise error in user defined function
- SQL Server Management Studio Tips : How to activate saving table modifications
- Understanding Object Ownership in sql 2000(how to change the schema table name in sql 2000)
- How to Remove Table Partitioning in SQL Server
- [Tips] How to Add New field into Shapefile attribute table in ArcGIS ?
- How to find duplicate rows with SQL
- 【MySQL笔记】解除输入的安全模式,Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.
- sql: Query to Display Foreign Key Relationships and Name of the Constraint for Each Table in Database
- How to Alter a Replicated Article in SQL Server 2005
- How to duplicate a UIButton in Objective C?
- How to control PrincipalObjectAccess table growth in Microsoft Dynamics CRM 2011
- Error message when you try to save a table in SQL Server 2008: "Saving changes is not permitted"