crashmaster Posted February 18, 2010 Share Posted February 18, 2010 Hi there, have problem with one thing. I have a database table with similar structure for ex.: id | name _______ 1 | Cat 2 | Dog 3 | Wolf 4 | Elephant 5 | Tiger 6 | Lion 7 | Bird All I want to do is: how, by 1 simple query, select an animal with id = 4 and also how to get one previous and one next animal id ?? thanks for reply ) Quote Link to comment https://forums.phpfreaks.com/topic/192487-very-simple-query/ Share on other sites More sharing options...
kickstart Posted February 18, 2010 Share Posted February 18, 2010 Hi Crude way of doing it:- SELECT id, name FROM SomeTable WHERE id = 4 UNION (SELECT id, name FROM SomeTable WHERE id > 4 ORDER BY id LIMIT 1 ) UNION (SELECT id, name FROM SomeTable WHERE id < 4 ORDER BY id DESC LIMIT 1 ) All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/192487-very-simple-query/#findComment-1014232 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.