MySQL Forums
Forum List  »  General

combine this 2 simple querys into 1 query for performance.
Posted by: oshri cohen
Date: September 13, 2011 06:14AM

hi friends.
first of all - sorry on my english ;-).
i have table calld users with the following records :

user_id user_name
1 alex
2 robert
3 sam
4 mike
5 jhon
6 kevin
7 blink
8 jek
9 stefeni

i want to write query that give me the 5 next users of specific user , for example :
"select * from users where user_id>2 order by user_id limit 5" give you user_id 3,4,5,6,7 - its work fine when the user_id not in the bottom of the table (like id:6,7,8,9)
and hence when the user_id in the bottom i need always to check if i get 5 users, if not i select the rest of the users from the start, circular way.
for example: the five users that come after user_id=8 are: 9,1,2,3,4

today i'm doing thats with 2 query, anyone think that can be done with one query...?
your help is welcome.

Options: ReplyQuote


Subject
Written By
Posted
combine this 2 simple querys into 1 query for performance.
September 13, 2011 06:14AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.