Owen
Owen

Reputation: 7577

mySQL select IN range

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);

Upvotes: 109

Views: 160158

Answers (2)

Lalit Dashora
Lalit Dashora

Reputation: 485

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

SELECT JOB FROM MYTABLE WHERE ID BETWEEN 10 AND 15;

Upvotes: 7

ESG
ESG

Reputation: 9425

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

Upvotes: 208

Related Questions