FábioMartinho
FábioMartinho

Reputation: 49

PHP with MySQL WHERE Value Range

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.

Upvotes: 0

Views: 111

Answers (1)

Marc B
Marc B

Reputation: 360572

SELECT ...
...
WHERE nums (BETWEEN ($num - 2) AND ($num + 2))
   AND (nums <> $num)

Upvotes: 2

Related Questions