I need to get the IDs around an ID with mySQL.
Example:
IDs in the table:
2, 4, 5, 9, 11, 15, 19, 22, 25
I need to know the 5 IDs around the ID 9, for example.
The query should return:
4, 5, 9, 11, 15
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A possible solution would be to
SQL Statement
Edit (thx to ypercube for pointing out a possible flaw in this solution)
If the intent is to get 2 id’s from the left and two id’s from the right, the statement can be adjusted as follows