SQL to find number within a range of two fields of Mysql table

0

My Mysql table has the following fields:

id;
num_min;
num_max;

The user will enter a number and need to verify that this number is in the interval between the num_min and num_max column of the table.

I tried with between but it did not work!

Is it possible to do this directly using a mysql query or does it have to be done via php?

    
asked by anonymous 06.03.2018 / 19:15

1 answer

2

Make sure your syntax for between is correct:

SELECT * FROM tabela_nome WHERE $valor BETWEEN num_min AND num_max;

There is also this option:

SELECT * FROM tabela_nome WHERE $valor > num_min AND $valor < num_max;

But between is better, post as you did (code), the error may be in php

    
06.03.2018 / 19:32