[thelist] Problem with distinct

Luther, Ron Ron.Luther at hp.com
Tue Sep 11 10:17:20 CDT 2007

Bill Moseley asked:

>>    test=> select * from product_view;
>>     id | widget_name | color |  size  
>>    ----+-------------+-------+--------
>>      1 | widget A    | red   | large
>>      1 | widget A    | red   | medium
>>      1 | widget A    | red   | small
>>      1 | widget A    | blue  | large

>>Client:  "I want a list of widgets, and I want people to be 
>>able to select just "red" widgets, but I don't want to list a widget
more than once".

>>Well, you can't do this, of course, because you get the 
>>same widget more than once due to the multiple sizes:

Hi Bill,

Sorry to be late to the party, but I'm not seeing why you can't use
something like:

SELECT DISTINCT widget_name from product_view WHERE color='red';

That should produce a list of widgets that are available in red and only
list each such widget once.

(For me the 'select *' is evil and is the part that is hosing up your
query.  I'm kinda partial to 'select distinct'.)


More information about the thelist mailing list