English 中文(简体)
如何在表格中找到重复记录
原标题:How to find Duplicate Records in a Table

我在申请协会时工作。 NET C#

I want to view all the duplicated records in a Grid view Control.

I normally use “SqlDataSource” control.

请注意,我不想有一两条共同点的行文,我正试图找到除(PK)外一切相同的行文。

我希望大家理解这个问题。 感谢 您需要任何其他资料 请问我。

最佳回答
SELECT column1, column2, column3, column4, COUNT(1)
FROM yourtable
GROUP BY column1, column2, column3, column4
HAVING COUNT(1) > 1
问题回答

简而言之,最简单的办法是:

select column1, column2, ... /* all columns except ID */
from myTable
group by column1, column2, ... /* all columns except ID */
having count(*) > 1

您可以把记录整理成册,并记录在你的 que中:

select col1, col2, col3, count(1)
from table
group by col1, col2, col3
having count(1) > 1

There are several ways to do this, here is another:

SELECT t1.*
FROM MyTable t1
INNER JOIN MyTable t2
ON t1.field1 = t2.field1 AND t1.field2 = t2.field2 AND t1.field3 = t2.field3 ... etc ...
WHERE t1.PKID <> t2.PKID
select
    col1,
    col2,
    col3
from
(
    select 
        col1, 
        col2,
        col3,
        row_number() over(partition by Col1, Col2, Col3, ColN order by Col3) rownum
    from yourTable
)a
where rownum > 1

使用了ROW_NUMBER(>)功能,根据重复情况(partition by条)排列了你的记录。 然后选择所有重复的行文。

如果没有看到你确切的表层结构,这个通用塔就象我可以提供的那样具体。

谢谢大家,这是我所期待的。

select ProductID, Date, Category, COUNT(*)from Table1GROUP BY ProductID, Date, Category HAVING COUNT(*) > 1 -- gets only rows with more than 1 grouping




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签