0

I'm looking to build a select statement that checks if a number is in a specific set. For instance:

4000,5000,5500-5560,7244

Is it possible to build this into a mysql query, or do I have to manually build the query:

 Select * from table where x=4000 or x=5000 or x between 5500 and 5560 or x=7244

Thanks.

Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
Jonathan
  • 1,498
  • 2
  • 20
  • 41

2 Answers2

1

yes its possible to build this query but u need some ()

instead try this

   Select * from table where x in (4000,5000,7244 ) or x between 5500 and 5560 
echo_Me
  • 37,078
  • 5
  • 58
  • 78
  • would it be faster to just convert the ranges to discrete values and put them in the set (4000,5000,7244,5500,5501...5560)? – Jonathan Feb 22 '13 at 20:19
  • it little better and shorter and will not conflict if you have some more of `AND` and `OR` . about speed i didnt check it . – echo_Me Feb 22 '13 at 20:21
  • here they talk about performance and speed http://stackoverflow.com/questions/9926433/mysql-performance-in-clause-vs-equals-for-a-single-value – echo_Me Feb 22 '13 at 20:24
1

Looks like this would be the best query:

SELECT * FROM table WHERE x IN (4000, 5000, 7244) OR (x >= 5500 AND x <= 5560);