Answer the question
In order to leave comments, you need to log in
[Solved] MySQL query?
Friends, the head does not cook, help the collective mind.
Let's assume the situation.
MySQL table with one field `id`
id
1
2
3
4
5
6
7
8
9
10
You need to select the last 5 records that are greater than 2 with the condition that the id sort is ascending. — i.e. the result should be 6,7,8,9,10
SELECT * FROM `table` WHERE id > '2' ORDER BY id ASC LIMIT 5
SELECT * FROM `table` WHERE id > '2' ORDER BY id DESC LIMIT 5
Answer the question
In order to leave comments, you need to log in
(
SELECT *
FROM `table`
WHERE id > '2'
ORDER BY id DESC
LIMIT 5
)
ORDER BY id ASC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question