mySQL select IN range

Mysql

Mysql Problem Overview


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

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

Instead of

SELECT job FROM mytable WHERE id IN (10,11,12,13,14,15);

Mysql Solutions


Solution 1 - Mysql

You can't, but you can use BETWEEN

SELECT job FROM mytable WHERE id BETWEEN 10 AND 15

Note that BETWEEN is inclusive, and will include items with both id 10 and 15.

If you do not want inclusion, you'll have to fall back to using the > and < operators.

SELECT job FROM mytable WHERE id > 10 AND id < 15

Solution 2 - Mysql

To select data in numerical range you can use BETWEEN which is inclusive.

SELECT JOB FROM MYTABLE WHERE ID BETWEEN 10 AND 15;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOwenView Question on Stackoverflow
Solution 1 - MysqlESGView Answer on Stackoverflow
Solution 2 - MysqlLalit DashoraView Answer on Stackoverflow