WHERE expression comparing with set of values

This is a discussion on WHERE expression comparing with set of values within the MySQL Database forums, part of the Database Forums category; Hi folks, I want to find all rows where a certain column's value is within a set of values, ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-10-2008
plenty900@yahoo.com
 
Posts: n/a
Default WHERE expression comparing with set of values

Hi folks,

I want to find all rows where a certain column's value
is within a set of values, e.g. HAIRCOLOR is in the set
{'blue', 'red', 'green', 'blonde'}.

Is there any easy way to check for a value being
in a set, or do I need to do something like
(HAIRCOLOR='blue' OR HAIRCOLOR='red' ... )?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 01-10-2008
Gordon Burditt
 
Posts: n/a
Default Re: WHERE expression comparing with set of values

>I want to find all rows where a certain column's value
>is within a set of values, e.g. HAIRCOLOR is in the set
>{'blue', 'red', 'green', 'blonde'}.


SELECT ...whatever... FROM TABLE
WHERE HAIRCOLOR IN ('blue', 'red', 'green', 'blonde');

>Is there any easy way to check for a value being
>in a set, or do I need to do something like
> (HAIRCOLOR='blue' OR HAIRCOLOR='red' ... )?


See above. Note also that this does NOT necessarily give you all
the blue-haired rows first. No order is implied. If you want order,
use ORDER BY.

Reply With Quote
  #3 (permalink)  
Old 01-10-2008
Captain Paralytic
 
Posts: n/a
Default Re: WHERE expression comparing with set of values

On 10 Jan, 02:22, gordonb.ys...@burditt.org (Gordon Burditt) wrote:
>
> See above. Note also that this does NOT necessarily give you all
> the blue-haired rows first. No order is implied. If you want order,
> use ORDER BY.


More to the point use

ORDER BY FINS_IN_SET('blue', 'red', 'green', 'blonde')
Reply With Quote
  #4 (permalink)  
Old 01-10-2008
Peter H. Coffin
 
Posts: n/a
Default Re: WHERE expression comparing with set of values

On Thu, 10 Jan 2008 01:28:21 -0800 (PST), Captain Paralytic wrote:
> On 10 Jan, 02:22, gordonb.ys...@burditt.org (Gordon Burditt) wrote:
>>
>> See above. Note also that this does NOT necessarily give you all
>> the blue-haired rows first. No order is implied. If you want order,
>> use ORDER BY.

>
> More to the point use
>
> ORDER BY FINS_IN_SET('blue', 'red', 'green', 'blonde')


er um "FIND_IN_SET()" I hope...

--
1. My Legions of Terror will have helmets with clear plexiglass visors,
not face-concealing ones.
--Peter Anspach's list of things to do as an Evil Overlord
Reply With Quote
  #5 (permalink)  
Old 01-10-2008
Captain Paralytic
 
Posts: n/a
Default Re: WHERE expression comparing with set of values

On 10 Jan, 13:41, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> On Thu, 10 Jan 2008 01:28:21 -0800 (PST), Captain Paralytic wrote:
> > On 10 Jan, 02:22, gordonb.ys...@burditt.org (Gordon Burditt) wrote:

>
> >> See above. Note also that this does NOT necessarily give you all
> >> the blue-haired rows first. No order is implied. If you want order,
> >> use ORDER BY.

>
> > More to the point use

>
> > ORDER BY FINS_IN_SET('blue', 'red', 'green', 'blonde')

>
> er um "FIND_IN_SET()" I hope...

My one works well with fish!
Reply With Quote
  #6 (permalink)  
Old 01-10-2008
Peter H. Coffin
 
Posts: n/a
Default Re: WHERE expression comparing with set of values

On Thu, 10 Jan 2008 06:07:42 -0800 (PST), Captain Paralytic wrote:
> On 10 Jan, 13:41, "Peter H. Coffin" <hell...@ninehells.com> wrote:
>> On Thu, 10 Jan 2008 01:28:21 -0800 (PST), Captain Paralytic wrote:
>> > On 10 Jan, 02:22, gordonb.ys...@burditt.org (Gordon Burditt) wrote:

>>
>> >> See above. Note also that this does NOT necessarily give you all
>> >> the blue-haired rows first. No order is implied. If you want order,
>> >> use ORDER BY.

>>
>> > More to the point use

>>
>> > ORDER BY FINS_IN_SET('blue', 'red', 'green', 'blonde')

>>
>> er um "FIND_IN_SET()" I hope...

> My one works well with fish!


So do worms, but I'm not sure I want to see them in 3rd normal form...
(;

--
I hate mornings. I know they hate me back, too.
-- Joel Gluth
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:46 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0