[thelist] Problem with distinct

Matt Warden mwarden at gmail.com
Fri Sep 7 16:49:27 CDT 2007

On 9/7/07, Bill Moseley <moseley at hank.org> wrote:
> Client says:  "I want to be able to sort the widget list by its color".
> Developer: "But you can't do that because a widget might have more
> than one color.  Which color would would you sort by?"
> Client: "90% of our widgets only have one color, so sort by that color.  For
> the very few that have more than one color I don't care which one is used
> for sorting."

Distinct is evil

try this:

select widget_name, max(color)
from t_widgets
where color='red'
group by widget_name
order by widget_name

Not entirely sure it will allow you to do that on a varchar...

Matt Warden
Cincinnati, OH, USA

This email proudly and graciously contributes to entropy.

More information about the thelist mailing list