alconebay Posted September 16, 2009 Share Posted September 16, 2009 I need a query to select a row that contains the number that is closest to (and also higher than) a particular number. So say my number is 5 and my table has rows with 1, 4, 7, and 12 in it. I would need the query to select the row that has 7 in it. SELECT * FROM schedule WHERE ?? Quote Link to comment https://forums.phpfreaks.com/topic/174511-solved-select-row-with-number-closest-to-and-higher-than-x/ Share on other sites More sharing options...
gevans Posted September 16, 2009 Share Posted September 16, 2009 OK, so lets say the field in your table `schedule` was `numbers` `numbers` contains 1, 4, 7 and 12 as you said $comp = 5;//your comparison $query = "SELECT * FROM `schedule` WHERE `numbers` > $comp ORDER BY `numbrs` ASC LIMIT 1"; Quote Link to comment https://forums.phpfreaks.com/topic/174511-solved-select-row-with-number-closest-to-and-higher-than-x/#findComment-919757 Share on other sites More sharing options...
alconebay Posted September 16, 2009 Author Share Posted September 16, 2009 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/174511-solved-select-row-with-number-closest-to-and-higher-than-x/#findComment-919760 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.