Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
like this,
To retrieve top n rows
SELECT TOP(5)* FROM table1
Posted

1 solution

Please note that TOP 5 without ORDER BY may return any 5 rows from the table. In order to return first or last rows you need to define what first and last means. You do that using ORDER BY clause. So no there is no way to retrieve last 5 rows without using any columns in the query. Always use ORDER BY with TOP to get predictable results!
 
Share this answer
 
v2
Comments
Maciej Los 4-Dec-14 7:06am    
+5!
mudgilsks 5-Dec-14 1:51am    
Use DESC in order by clause or Use ROW NUMBER BY PARTITION Feature


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900