Forum Moderators: coopster

Message Too Old, No Replies

MySQL sytax for selecting items in database

Use of 'OR' statement to get range of values

         

s9901470

10:30 am on Apr 22, 2005 (gmt 0)

10+ Year Member



Hi

Can anyone tell me how to use an 'OR' statement with MySQL to select a range of values:

SELECT * FROM table WHERE staffid >=26 OR <=65

This doesn't work but I thought it might. I want to select those in the table with staff if 26 to 65.

Many thanks

coopster

10:42 am on Apr 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are telling it to return rows where one or the other is true. So basically, everything.

If you want both conditions to be true before returning any rows, use AND. (Or in this case, you could use BETWEEN to get the inclusive range).

[dev.mysql.com...]

s9901470

10:48 am on Apr 22, 2005 (gmt 0)

10+ Year Member



Got it!

SELECT * FROM table WHERE (staffid >=26) AND (staffid <=65)

Many thanks

Spudstr

3:41 pm on Apr 22, 2005 (gmt 0)

10+ Year Member



or..

SELECT * FROM table WHERE staffid between 26 and 65

should work tooo