watsmyname Posted August 22, 2010 Share Posted August 22, 2010 Hello, Suppose i have a table structure mID pointtoIncrease amountFrom amountTo 1 0 0 99 2 1 100 499 3 3 500 999 4 5 1000 1499 I have to select "pointoIncrease" for given amount. Like i have amount 550, then the point is 3 because 550 lies between amountFrom=500 and amountTo=999. Sounds simple but i m not being able to write a query for that, can anyone please help me. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/211426-selecting-a-row-for-a-given-amount/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 22, 2010 Share Posted August 22, 2010 SELECT pointtoIncrease FROM your_table WHERE amount BETWEEN amountFrom AND amountTo Quote Link to comment https://forums.phpfreaks.com/topic/211426-selecting-a-row-for-a-given-amount/#findComment-1102364 Share on other sites More sharing options...
watsmyname Posted August 22, 2010 Author Share Posted August 22, 2010 SELECT pointtoIncrease FROM your_table WHERE amount BETWEEN amountFrom AND amountTo Thanks for the reply, i think query is not working. The query is SELECT pointtoIncrease FROM sa_mileagepoints WHERE '1000' BETWEEN amountFrom AND amountTo So, it should result 5 only, but the query is returning 3 rows, 1,5 and 0 and if amount is 550, it returns two rows 3 and 0 Quote Link to comment https://forums.phpfreaks.com/topic/211426-selecting-a-row-for-a-given-amount/#findComment-1102368 Share on other sites More sharing options...
PFMaBiSmAd Posted August 22, 2010 Share Posted August 22, 2010 What is the data type of your amountFrom and amountTo columns? It would need to be an INT for math comparisons to work. Also, by putting the '1000' inside of single-quotes in the query, that makes it a string and strings are compared character by character starting with the left-most character. Quote Link to comment https://forums.phpfreaks.com/topic/211426-selecting-a-row-for-a-given-amount/#findComment-1102373 Share on other sites More sharing options...
watsmyname Posted August 22, 2010 Author Share Posted August 22, 2010 What is the data type of your amountFrom and amountTo columns? It would need to be an INT for math comparisons to work. Also, by putting the '1000' inside of single-quotes in the query, that makes it a string and strings are compared character by character starting with the left-most character. Oh thanks, got it the single quotes was causing a problem, thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/211426-selecting-a-row-for-a-given-amount/#findComment-1102374 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.