How to query the next row

83
October 15, 2018, at 11:00 PM

I have a table containing a column AGE contains these values:

5
2
10
4
1

How can I select everything after where AGE=2 and the next row has Age=10?

My desired results should be:

4
1
Answer 1

In SQL (including MySQL) tables are considered to be "unordered" and the sequence of data entry is not guaranteed to be the sequence of rows when you query that data. The "default order" of any data can be whatever happens as the database reads from storage - which is not guaranteed to be in any sensible order.

You HAVE to apply an ORDER BY clause to guarantee a predictable sequence.

So if you are relying on a sequence have some way to replicate that sequence through an order by clause.

READ ALSO
Group by comma separated flield

Group by comma separated flield

Is it possible to group over a comma separated mysql field? i have a mysql database with a column with comma separated ids

75
Foreign Key explaination

Foreign Key explaination

ChatBox Table - ID(FK),RoomID(FK),UserID(FK),Text,created_at

125
Detect first change in column value results

Detect first change in column value results

I'm trying to get a divider in am automated select menu

76