0

So, I have a variable with a certain integer. Let's call it $num. What I'd like to do is to check in a table called nums where I have value(s) between or equal to $num-2 and $num+2 but not equal to $num.

Mathematically, this range would be like [$num-2,$num[ ; ]$num,$num+2].

SELECT num FROM nums WHERE ...

I know this is basic querying but I'm kind of confused right now. Thanks in advance.

1 Answer 1

2
SELECT ...
...
WHERE nums (BETWEEN ($num - 2) AND ($num + 2))
   AND (nums <> $num)
Sign up to request clarification or add additional context in comments.

3 Comments

Does BETWEEN include $num-2 and $num+2? Or is it like $num-2<x and x<$num+2?
X between A and B is the equivalent of (A <= X) && (X <= B).
Ok, thanks. I'll accept your answer in 6 minutes since it doesn't allow me to do it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.