RE: simplifying OR clauses

2004-05-02 Thread Matt Chatterley
As others have said, you can use 'IN'. You could also use UNION (although I
don't think I would, personally, for quite what you want!):

SELECT word FROM word_table WHERE id = 1
UNION
SELECT word FROM word_table WHERE id = 2

Etc. Assuming your version of MySQL supports the UNION operator!

Another option (although less elegant than 'IN') is to create a temporary
table with one column, 'word_id' or similar, and insert all of the IDs you
wish to search for in there. You can then INNER JOIN to that table:

SELECT word FROM word_table wt INNER JOIN id_table it ON it.word_id = wt.id

It all depends on how you're doing this, and exactly what you want. :)

Cheers,

Matt

 -Original Message-
 From: Matthias Eireiner [mailto:[EMAIL PROTECTED]
 Sent: 26 April 2004 23:00
 To: [EMAIL PROTECTED]
 Subject: simplifying OR clauses
 
 hi there,
 
 I have a basic question:
 how can I simplify multiple OR statements in a WHERE clause where I have
 only one column to which I refer?
 
 e.g.
 
 SELECT word FROM word_table WHERE id = 1 OR id = 34 OR id = 78 OR id =
 8787
 OR ...
 
 I thought I once read over something like this but I can't find it right
 now. Would be great if somebody could help me out!
 Thanks a lot in advance!
 
 regards
 
 Matthias
 
 
 _
 
 Matthias Eireiner
 
 email: [EMAIL PROTECTED]
 
 www.bvcapital.com
 _
 
 
 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: simplifying OR clauses

2004-04-26 Thread Keith C. Ivey
On 26 Apr 2004 at 14:59, Matthias Eireiner wrote:

 how can I simplify multiple OR statements in a WHERE clause where I
 have only one column to which I refer?
 
 e.g. 
 
 SELECT word FROM word_table WHERE id = 1 OR id = 34 OR id = 78 OR id =
 8787 OR ...

You want the IN operator:

http://dev.mysql.com/doc/mysql/en/Comparison_Operators.html#IDX1209

-- 
Keith C. Ivey [EMAIL PROTECTED]
Tobacco Documents Online
http://tobaccodocuments.org


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: simplifying OR clauses

2004-04-26 Thread Garth Webb
On Mon, 2004-04-26 at 14:59, Matthias Eireiner wrote:
 hi there,
 
 I have a basic question:
 how can I simplify multiple OR statements in a WHERE clause where I have
 only one column to which I refer?
 
 e.g. 
 
 SELECT word FROM word_table WHERE id = 1 OR id = 34 OR id = 78 OR id = 8787
 OR ...

Try 'IN':

  SELECT word FROM word_table WHERE id IN (1, 34, 78, 8787);

 I thought I once read over something like this but I can't find it right
 now. Would be great if somebody could help me out!
 Thanks a lot in advance!
 
 regards
 
 Matthias
 
 
 _
 
 Matthias Eireiner
 
 email: [EMAIL PROTECTED]
 
 www.bvcapital.com
 _
 

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]