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

Asked

Viewed 1,220 times

0

My Mysql table has the following fields:

id;
num_min;
num_max;

The user will enter a number and need to check if that number is in the range between the column num_min and num_max of the table.

I tried with between but it didn’t work!

You can do this directly using a mysql query or it has to be done via php?

1 answer

1


Check that your between syntax 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

  • Thanks, it worked out!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.