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 ) 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 Link to comment https://forums.phpfreaks.com/topic/192487-very-simple-query/#findComment-1014232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.