[thelist] sql de-doupe

Brian Cummiskey brian at hondaswap.com
Sat Feb 2 15:03:10 CST 2008

r937 wrote:
>> modelA  cat1
>> modelA  cat2
>> modelB  cat1
>> modelB  cat2
>> Out of those 4, I need:
>> modelA  whatever_cat_comes_first
>> modelB  whatever_cat_comes_first
> unfortunately there is no such thing as "comes first" in a relational 
> database
> (despite this, msaccess has a FIRST function, but SQL Server doesn't)
> how about the lowest category?
>    select model, min(cat) from daTable group by model
> simple, yes?

Hi Rudy,

It doesn't matter which category comes in...  so while it might be catA 
the first time it runs or catB the second time it runs, the order is not 

cat is also a string.   I'm not sure if the min() function will work as 
desired on the varchar field.

I'd like to use a group by, but there's about 20 extra fields besides 
those two in the query, and grouping by all of those won't disclude 
variants in other fields (which again are not important...  I simply 
need just one instance)

More information about the thelist mailing list