Page 1 of 1

An SQL question.

Posted: Thu Mar 29, 2007 7:15 pm
by JellyFish
Sorry I don't know if this is in the right forum.

Question:

How could I select the rows where the field "entry" is either "foo" or "bar"?

I think something like:

Code: Select all


SELECT class, entry, value FROM $table_name WHERE class = 'manager' AND entry = ('foo' OR 'bar');

Would this work or is there a correct way?

Also, to I have to select class and entry in order to use these fields in the WHERE clause?

Thank for reading my post. I'd appreciate any help on this. :D

Re: An SQL question.

Posted: Thu Mar 29, 2007 7:27 pm
by nickvd
JellyFish wrote:Sorry I don't know if this is in the right forum.
Nope! :)
JellyFish wrote:

Code: Select all

SELECT class, entry, value FROM $table_name WHERE class = 'manager' AND entry = ('foo' OR 'bar');

Code: Select all

SELECT `class`, `entry`, `value` FROM $table_name WHERE `class` = 'manager' AND `entry` = 'foo' OR `entry` = 'bar';
--or--

Code: Select all

SELECT `class`, `entry`, `value` FROM $table_name WHERE `class` = 'manager' AND `entry` IN ('foo','bar');
JellyFish wrote:Also, do I have to select class and entry in order to use these fields in the WHERE clause?
Nope...

Posted: Thu Mar 29, 2007 7:49 pm
by JellyFish
Thanks nickvd! I knew there was something to it.

IN clause seems great! What's it saying? So that I know how to remember it.

Posted: Thu Mar 29, 2007 7:52 pm
by Luke
SQL is related to databases... moved to databases.

Posted: Thu Mar 29, 2007 9:03 pm
by nickvd
JellyFish wrote:Thanks nickvd! I knew there was something to it.

IN clause seems great! What's it saying? So that I know how to remember it.
think of php's in_array()...

<edit>

And again, a little less cryptic...

If the value in `entry` is IN these ('this','that','otherthing')