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 ?? 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"; 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! 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
Archived
This topic is now archived and is closed to further replies.