Adam
Adam

Reputation: 9449

MySQL WHERE Clause between two values

I'm attempting to select all the rows based on whether or not it falls within the limits of two numbers. For example, I want all the rows who's limits include the number 4. So if a row that had a start value of 2 and end value of 7 would be returned. Here's what I have so far:

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

Upvotes: 1

Views: 2807

Answers (2)

Fabio
Fabio

Reputation: 23480

I think your query is wrong, as you said: if a row that had a start value of 2 and end value of 7 would be returned you will need this query

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

Upvotes: 0

user2989408
user2989408

Reputation: 3137

If a row that had a start value of 2 and end value of 7 should be returned then your filter condition should be as shown here.

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

Upvotes: 1

Related Questions