Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Using SQL to obtain unique values, a guilty pleasure

I have a list of int IDs of individuals associated with a subject, with the list coming from various sources.  There are most likely duplicates, but I want unique values only.

I considered what type of algorithm I would use.  An array perhaps, sort it and compare.  Quick sort?  Double-linked list?  Binary tree?  (I'm being ridiculous now.  Sorry.)  But then it hit me that all of the user IDs, regardless of their origination, were found in a users SQL table, so after obtaining a team_ids string which looked something like '3,44,313,313,12', I turned to SQL to be my brains:

 sql = "select distinct id from users where id in (" + team_ids + ") order by id";
 SqlDataReader dr = SQLHelper.ExecuteReader(sql);
 while (dr.Read())...
 

KISS, baby.

Comments (0) | Post RSS RSS comment feed

Posted on 4/28/2004 1:01:00 PM by Dave Burke
Categories:
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke