MySQL select range IN

Is it possible to define a range for the IN query part, something like this

SELECT job FROM mytable WHERE id IN (10..15); 

Instead

 SELECT job FROM mytable WHERE id IN (10,11,12,13,14,15); 
+46
mysql
May 14 '12 at 15:08
source share
2 answers

You cannot, but you can use BETWEEN

 SELECT job FROM mytable WHERE id BETWEEN 10 AND 15 

Please note that BETWEEN is inclusive and will contain elements with identifiers 10 and 15.

If you do not want to include, you will have to revert to using the > and < operators.

 SELECT job FROM mytable WHERE id > 10 AND id < 15 
+90
May 14, '12 at 15:10
source share

To select data in a numerical range, you can use BETWEEN , which is included.

 SELECT JOB FROM MYTABLE WHERE ID BETWEEN 10 AND 15; 
+1
Jul 13 '17 at 5:49
source share



All Articles