MySQL WHERE两个值之间的子句

时间:2014-03-18 19:18:01

标签: mysql sql select

我试图根据它是否在两个数字的范围内来选择所有行。例如,我希望所有限制的行都包含数字4.因此,如果返回一个起始值为2且结束值为7的行。这就是我到目前为止所拥有的:

SELECT *
FROM egw_scripture_reference
WHERE book = 'Revelation'
  AND end_verse <= 4 
  AND start_verse >= 4

2 个答案:

答案 0 :(得分:1)

如果a row that had a start value of 2 and end value of 7 should be returned,则您的过滤条件应如下所示。

SELECT * FROM egw_scripture_reference 
WHERE book = 'Revelation' AND end_verse >= 4 AND start_verse <= 4

答案 1 :(得分:0)

我认为您的查询错误,正如您所说:如果返回值为2且结束值为7的行,则需要此查询

SELECT * 
FROM egw_scripture_reference 
WHERE book = 'Revelation' 
AND end_verse >= 4 
AND start_verse <= 4