Page 1 of 1

Getting value between two values in DB

Posted: Sat Nov 24, 2007 3:13 pm
by GeXus
I have a table with from_value and to_value... I want to return the results where value X is between from_value and to_value...

so I will have a value such as 25... then I want to select which record it is associated to based on the from_value and to_value values in the DB...


Any idea how I can do that? It's probably dead simple.. but I'm not getting it... thanks!

Posted: Sat Nov 24, 2007 6:33 pm
by Benjamin
Can you elaborate a little? I don't fully understand what your trying to do.

Maybe post the table structure.

Posted: Sat Nov 24, 2007 7:45 pm
by GeXus
Sure, so I have a table like this

id
name
from_value
to_value


Then I have a quiz with 5 questions and 5 options per question... each option is worth a certain value... The values of each is totaled and I want to return the row from the above table where that value is in between the from_value and to_value

Posted: Sat Nov 24, 2007 9:35 pm
by califdon
GeXus wrote:Sure, so I have a table like this

id
name
from_value
to_value

Then I have a quiz with 5 questions and 5 options per question... each option is worth a certain value... The values of each is totaled and I want to return the row from the above table where that value is in between the from_value and to_value

Code: Select all

SELECT * FROM [tablename] WHERE $myvalue >= `from_value` AND $myvalue <= `to_value`
should do it.

Posted: Sat Nov 24, 2007 9:52 pm
by GeXus
Haha, nice.. thank you!!