An SQL question.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

An SQL question.

Post 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
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Re: An SQL question.

Post 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...
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

SQL is related to databases... moved to databases.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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')
Post Reply