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, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
>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. |
|
|||
|
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') |
|
|||
|
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 |
|
|||
|
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! |
|
|||
|
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 |