mySQL select IN range

后端 未结 2 1616
醉酒成梦
醉酒成梦 2020-12-07 13:55

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

相关标签:
2条回答
  • 2020-12-07 14:40

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

    SELECT JOB FROM MYTABLE WHERE ID BETWEEN 10 AND 15;
    
    0 讨论(0)
  • 2020-12-07 14:44

    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
    
    0 讨论(0)
提交回复
热议问题