Is there an equivalent to top for getting the bottom rows?
Is there an equivalent to top for getting the bottom rows?
However: The correct answer should be that there is not, and cannot be, an equivalent to TOP for getting the bottom rows. It would seem that any of the answers which implement an ORDER BY clause in the solution is missing the point, or does not actually understand what TOP returns to you.
How to select bottom most rows in SQL?
Select TOP itself is “random” in theory, and this is the correct implementation for Select BOTTOM. In a table of 5000 records, bottom 1000 is everything except top 4000. – tzachs Aug 5 ’15 at 14:48
Do you know the difference between bottom N Records?
So — the bottom line here (pun intended) is that someone who is asking for the BOTTOM N records doesn’t actually know what they’re asking for. Or, at least, what they’re asking for and what BOTTOM actually means are not the same thing.
How to select top and bottom rows in MSG 4108?
If you put the ROW_NUMBER…in the WHERE you get Msg 4108, Level 15, State 1, Line 1 Windowed functions can only appear in the SELECT or ORDER BY clauses. You need to wrap the SELECT and FROM in a derived table and pull the WHERE to the outer query for this to work, like @Paul did in the second method in his answer. – KM.
How to retrieve top and bottom rows together?
I had to find TOP 1 and BOTTOM 1 record together. I right away that I should just do UNION but then I realize that UNION will not work as it will only accept one ORDER BY clause. If you specify more than one ORDER BY clause. It will give an error. Let us see how we can retrieve top and bottom rows together.
Select TOP itself is “random” in theory, and this is the correct implementation for Select BOTTOM. In a table of 5000 records, bottom 1000 is everything except top 4000. – tzachs Aug 5 ’15 at 14:48
Which is the second last row in the resultset?
In this following diagram you can notice that there are two rows which are with ProductID 712 and 715. The entire resultset is ordered by column ProductID. Now our final requirement is that we want row 715 to be the second last row in the resultset and 712 as a very last row in the resultset.
So — the bottom line here (pun intended) is that someone who is asking for the BOTTOM N records doesn’t actually know what they’re asking for. Or, at least, what they’re asking for and what BOTTOM actually means are not the same thing.