Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL order by after more than

Tags:

sql

mysql

I am trying SQL to sort results

id | name (table name: student)
-----
1 | jhon
2 | amin
3 | heli
4 | mir
5 | mrs
6 | amr
7 | jonnathan
8 | adhy

When i use this query

select id from studenth where id>='3' order by id DESC limit 2

The result that appears is

id | name (table name: student)
-----
8 | adhy
7 | jonnathan

Whereas I want to sort results after id = 3, I want the data as below

id | name (table name: student)
-----
4 | mir
3 | heli
like image 545
Adhy Musaad Avatar asked Dec 04 '25 10:12

Adhy Musaad


1 Answers

select * from (select id from student where id >= 3 order by id limit 2) r order by r.id desc
like image 146
wannadream Avatar answered Dec 07 '25 10:12

wannadream



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!