Finding Distinct records in a datatable

  • Thread starter Thread starter Neil
  • Start date Start date
N

Neil

Hi,

I have a dataset which contains one datatable, with the
structure below:

EntityId|SegmentId|Volume
1 1 5
1 3 7
1 2 9
2 1 5
2 2 4

Is the anyway I can filter this datatable to give me a
list of Distinct EntityIds? At the moment I have created
a new datatable with one column, I loop through the first
data table and check if the current EntityId is in the
new table if it is not I add it else I move to the next
EntityId.

I'm hoping there is a simpler way to do this...?
 
Currently, you can filter results based on any of the columns, but not to
get only one instance (DISTINCT).

An option is to piggy back a DISTINCT query to the the sproc (or SQL
statement, if you are not in a RDBMS) that creates the DataSet. You will
then have a second table you can query rather than loop. It will be far more
efficient to have two tables than to loop through every item, esp. with
larger result sets.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Thanks for your help, the reason I'm wanting to do this
is a bit more complicated, I could achieve what I want by
writing an SQL cursor but i'm trying to take some of the
load of the DB which is already working pretty hard while
the webserver sits around.

Cheers
 
Thanks, this is essentially what I'm doing at the moment,
I was kinda hoping there would be a method to do this but
looks like I will implemement my own helper class.
 
Back
Top