Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of SELECT TOP?

Tags:

sql

sql-server

Transact-SQL has a handy SELECT TOP 4 [whatever] FROM.........

I want to make a SELECT query returning the last "n" entries from a table instead of the first ones.

This is the query I would use to return the first four items entered at the table, using SELECT TOP:

sql = "SELECT TOP 4 [news_title], [news_date_added], [news_short_description],
[news_ID] FROM [Web_Xtr_News] WHERE ([news_type] = 2 OR [news_type] = 3) AND
[news_language] = '" + Language + "' ORDER BY [news_ID] ASC"

I need to return the last four.

like image 554
Baron Von Peter Wright Avatar asked May 17 '12 11:05

Baron Von Peter Wright


1 Answers

Change the order of the table from ASC to DESC.

like image 171
Oded Avatar answered Sep 18 '22 15:09

Oded