BilalAhmed
BilalAhmed

Reputation: 191

Remove Duplicate rows from DataGrid

I am using ASP.NET DataGrid Class. asp:DataGrid I want to remove certain rows based on the following condition.

For Example:

Complaint-Number        Attempts   Time
6000000939              1          11:02:00
6000000939              2          11:04:00
6000000939              3          11:09:00

I want to keep only those Complaints which has the highest Attempts like.

Complaint-Number        Attempts   Time
6000000939              3          11:09:00

I tried this Example but still no luck Eliminate Duplicate

NOTE: Please note that I am using asp:DataGrid class.

Please find the Screenshot of my report for your reference.

enter image description here

Upvotes: 4

Views: 383

Answers (2)

Salah Akbari
Salah Akbari

Reputation: 39976

In your Select statement try something like this.:

SELECT *
FROM yourTable 
WHERE (Attempts IN
               (SELECT MAX(Attempts) AS Expr1
                FROM yourTable AS yourTable_1))

It is called Subquery and you can read more about it here: Subquery Fundamentals.

Upvotes: 4

Munam Yousuf
Munam Yousuf

Reputation: 547

SELECT DISTINCT Complaint-Number FROM yourtable ORDER BY Attempts ASC

You can use ORDER BY Attempts DESC as you need.

Upvotes: 1

Related Questions