I have a list
that displays only 10 rows.
I need to select the next 10 and previous 10 rows.
However, the ID I use as reference are not exactly in order.
e.g:
1,2,5,10,15
How do I select the next few rows using the ID?
Let us now implement the above query. mysql> SELECT * FROM ( -> SELECT * FROM Last10RecordsDemo ORDER BY id DESC LIMIT 10 -> )Var1 -> -> ORDER BY id ASC; The following is the output that displays the last 10 records. We can match both records with the help of the SELECT statement.
To select first 10 elements from a database using SQL ORDER BY clause with LIMIT 10. Insert some records in the table using insert command. Display all records from the table using select statement. Here is the alternate query to select first 10 elements.
Using DESC will return the last N rows, but the returned rows will also be in reverse order from the first N rows.
I want to select the last 3 rows of an sql table. I know I should use SELECT * FROM table ORDER BY DESC LIMIT 3 , but the problem with this code is that it selects the rows from the end. For example, it selects 30, then 29, then 28.
you can try limit:
select * from `table` limit <startIndex>,<NumberOfRecords>;
example:-
select * from `user` limit 5,10;
This will return 10 rows starting from 6th row.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With