Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select bottom most rows?

I can do SELECT TOP (200) ... but why not BOTTOM (200)?

Well not to get into philosophy what I mean is, how can I do the equivalent of TOP (200) but in reverse (from the bottom, like you'd expect BOTTOM to do...)?

like image 739
MetaGuru Avatar asked Dec 09 '09 20:12

MetaGuru


People also ask

How do you select the bottom 3 rows in SQL?

Try only this:- SELECT * FROM reset ORDER BY ASC LIMIT (FOUND_ROWS() - 3), 3 and check if it is giving the last 3 rows from your table in ascending order!!!

How do I select the bottom 10 rows in SQL?

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.

How do I select the last 1000 rows in SQL Server?

From SSMS 2008 R2, right-clicking a table we can select "Edit Top 200 Rows" or "Select Top 1000 Rows."


2 Answers

SELECT     columns FROM (      SELECT TOP 200           columns      FROM           My_Table      ORDER BY           a_column DESC ) SQ ORDER BY      a_column ASC 
like image 134
Tom H Avatar answered Sep 26 '22 20:09

Tom H


It is unnecessary. You can use an ORDER BY and just change the sort to DESC to get the same effect.

like image 28
Justin Ethier Avatar answered Sep 22 '22 20:09

Justin Ethier