Last post Sep 13, 2011 09:19 AM by linuxman2
Sep 13, 2011 07:57 AM|linuxman2|LINK
first of all - sorry on my english ;-).
i have table calld users with the following records :
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.
Sep 13, 2011 08:43 AM|manishprajapati|LINK
SELECT TOP 5 * FROM Users WHERE User_ID > 2
Sep 13, 2011 08:51 AM|linuxman2|LINK
top function dosent work on mysql only mssql - any other idea ?
or did you know how implement it on mysql .. ?
Sep 13, 2011 09:19 AM|linuxman2|LINK
i find the solution whith UNION funtion !
thank for all helpers !!