Chris Hansen Posted August 13, 2009 Share Posted August 13, 2009 Hi I need to select the rows before and after a specified row. If my database looks like: ID 100 101 103 111 120 - The specified id 180 190 200 201 ID 120 is specified and I want to retrieve the 4 rows before and after that row (the green ones). How can this be done in PHP? Thanks for any help and I hope it makes sense, Andy Quote Link to comment https://forums.phpfreaks.com/topic/170146-selecting-rows-before-and-after-an-id/ Share on other sites More sharing options...
kickstart Posted August 13, 2009 Share Posted August 13, 2009 Hi Crude way. SELECT * FROM ( (SELECT * FROM SomeTable WHERE ID <15 ORDER BY ID DESC LIMIT 0 , 4) UNION (SELECT * FROM SomeTable WHERE ID >15 ORDER BY ID ASC LIMIT 0 , 4))Deriv1 ORDER BY ID ASC All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/170146-selecting-rows-before-and-after-an-id/#findComment-897547 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.