query for two different values from one field

This is a discussion on query for two different values from one field within the MySQL Database forums, part of the Database Forums category; I have a field that stores one of three possible answers: yes, no, maybe and I know that if I ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-28-2008
canajien@gmail.com
 
Posts: n/a
Default query for two different values from one field

I have a field that stores one of three possible answers: yes, no,
maybe

and I know that if I write:

SELECT *
FROM table
WHERE field = "yes"

I will get all the records where the field = yes, but how do I get it
to return all the records when the field equal yes or maybe

thanks
Reply With Quote
  #2 (permalink)  
Old 03-28-2008
Erick T. Barkhuis
 
Posts: n/a
Default Re: query for two different values from one field

canajien@gmail.com:
> I have a field that stores one of three possible answers: yes, no,
> maybe
>
> and I know that if I write:
>
> SELECT *
> FROM table
> WHERE field = "yes"
>
> I will get all the records where the field = yes, but how do I get it
> to return all the records when the field equal yes or maybe


SELECT *
FROM table
WHERE field = "theFemaleAnswer"

--
Erick
[scnr]
Reply With Quote
  #3 (permalink)  
Old 03-28-2008
Peter H. Coffin
 
Posts: n/a
Default Re: query for two different values from one field

On Fri, 28 Mar 2008 08:40:51 -0700 (PDT), canajien@gmail.com wrote:
> I have a field that stores one of three possible answers: yes, no,
> maybe
>
> and I know that if I write:
>
> SELECT *
> FROM table
> WHERE field = "yes"
>
> I will get all the records where the field = yes, but how do I get it
> to return all the records when the field equal yes or maybe


Look up the logical construct "OR" in combination with SELECT.

We hope you get an A on your quiz.

--
58. If it becomes necessary to escape, I will never stop to pose dramatically
and toss off a one-liner.
--Peter Anspach's list of things to do as an Evil Overlord
Reply With Quote
  #4 (permalink)  
Old 03-28-2008
canajien@gmail.com
 
Posts: n/a
Default Re: query for two different values from one field

On Mar 28, 12:03 pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> On Fri, 28 Mar 2008 08:40:51 -0700 (PDT), canaj...@gmail.com wrote:
> > I have a field that stores one of three possible answers: yes, no,
> > maybe

>
> > and I know that if I write:

>
> > SELECT *
> > FROM table
> > WHERE field = "yes"

>
> > I will get all the records where the field = yes, but how do I get it
> > to return all the records when the field equal yes or maybe

>
> Look up the logical construct "OR" in combination with SELECT.
>
> We hope you get an A on your quiz.
>
> --
> 58. If it becomes necessary to escape, I will never stop to pose dramatically
> and toss off a one-liner.
> --Peter Anspach's list of things to do as an Evil Overlord


i already tried that

SELECT *
FROM table
WHERE field = "yes"
OR field = "no"

and it didn't work

however I did a search on your hint and I read that I can use
brackets, so when I wrote it as:

SELECT *
FROM table
(WHERE field = "yes"
OR field = "no")

it did work, don't ask me why.

BTW it's not a quiz I am just bored at work today so I thought I would
brush up on a few things...

Thanks for the information it got me pointed in the right direction!!!
Reply With Quote
  #5 (permalink)  
Old 03-28-2008
ThanksButNo
 
Posts: n/a
Default Re: query for two different values from one field

On Mar 28, 8:40 am, "canaj...@gmail.com" <canaj...@gmail.com> wrote:
> I have a field that stores one of three possible answers: yes, no,
> maybe
>
> and I know that if I write:
>
> SELECT *
> FROM table
> WHERE field = "yes"
>
> I will get all the records where the field = yes, but how do I get it
> to return all the records when the field equal yes or maybe
>
> thanks


SELECT *
FROM table
WHERE field IN ('yes', 'maybe')
Reply With Quote
  #6 (permalink)  
Old 03-28-2008
ThanksButNo
 
Posts: n/a
Default Re: query for two different values from one field

On Mar 28, 8:45 am, Erick T. Barkhuis <erick.use-...@ardane.c-o-m>
wrote:
> canaj...@gmail.com:
>
> > I have a field that stores one of three possible answers: yes, no,
> > maybe

>
> > and I know that if I write:

>
> > SELECT *
> > FROM table
> > WHERE field = "yes"

>
> > I will get all the records where the field = yes, but how do I get it
> > to return all the records when the field equal yes or maybe

>
> SELECT *
> FROM table
> WHERE field = "theFemaleAnswer"
>
> --
> Erick
> [scnr]


No no no -- that would either return ALL records, or SOME of the
records, in a non-deterministic (but not random) fashion.
Reply With Quote
  #7 (permalink)  
Old 03-29-2008
log4work
 
Posts: n/a
Default Re: query for two different values from one field

I suggest to check:

SELECT *
FROM table
WHERE field IN ('YES', 'MAYBE', 'yes', 'maybe');

You can try to use some functions like upper, lower. Check what exactly is
inside your column and rows.


Uzytkownik "ThanksButNo" <no.no.thanks@gmail.com> napisal w wiadomosci
news:79a584ca-df4a-45f3-af80-f7030f38931c@s8g2000prg.googlegroups.com...
> On Mar 28, 8:40 am, "canaj...@gmail.com" <canaj...@gmail.com> wrote:
>> I have a field that stores one of three possible answers: yes, no,
>> maybe
>>
>> and I know that if I write:
>>
>> SELECT *
>> FROM table
>> WHERE field = "yes"
>>
>> I will get all the records where the field = yes, but how do I get it
>> to return all the records when the field equal yes or maybe
>>
>> thanks

>
> SELECT *
> FROM table
> WHERE field IN ('yes', 'maybe')



Reply With Quote
  #8 (permalink)  
Old 03-29-2008
log4work
 
Posts: n/a
Default Re: query for two different values from one field


Uzytkownik "ThanksButNo" <no.no.thanks@gmail.com> napisal w wiadomosci
news:79a584ca-df4a-45f3-af80-f7030f38931c@s8g2000prg.googlegroups.com...
> On Mar 28, 8:40 am, "canaj...@gmail.com" <canaj...@gmail.com> wrote:
>> I have a field that stores one of three possible answers: yes, no,
>> maybe
>>
>> and I know that if I write:
>>
>> SELECT *
>> FROM table
>> WHERE field = "yes"
>>
>> I will get all the records where the field = yes, but how do I get it
>> to return all the records when the field equal yes or maybe
>>
>> thanks

>
> SELECT *
> FROM table
> WHERE field IN ('yes', 'maybe')



I suggest to check:

SELECT *
FROM table
WHERE field IN ('YES', 'MAYBE', 'yes', 'maybe');

You can try to use some functions like upper, lower. Check what exactly is
inside your column and rows.


Reply With Quote
  #9 (permalink)  
Old 03-29-2008
Jerry Stuckle
 
Posts: n/a
Default Re: query for two different values from one field

log4work wrote:
> Uzytkownik "ThanksButNo" <no.no.thanks@gmail.com> napisal w wiadomosci
> news:79a584ca-df4a-45f3-af80-f7030f38931c@s8g2000prg.googlegroups.com...
>> On Mar 28, 8:40 am, "canaj...@gmail.com" <canaj...@gmail.com> wrote:
>>> I have a field that stores one of three possible answers: yes, no,
>>> maybe
>>>
>>> and I know that if I write:
>>>
>>> SELECT *
>>> FROM table
>>> WHERE field = "yes"
>>>
>>> I will get all the records where the field = yes, but how do I get it
>>> to return all the records when the field equal yes or maybe
>>>
>>> thanks

>> SELECT *
>> FROM table
>> WHERE field IN ('yes', 'maybe')

>
>
> I suggest to check:
>
> SELECT *
> FROM table
> WHERE field IN ('YES', 'MAYBE', 'yes', 'maybe');
>
> You can try to use some functions like upper, lower. Check what exactly is
> inside your column and rows.
>
>
>


Unnecessary, if this is character (non-binary) data. Comparisons are
case-insensitive.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
Reply


Thread Tools
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

vB 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 10:33 PM.


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