Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi a have this table
My table name is NEWS
and this fields: NewsId ,NewsTitle,NewsDate
a want get a query
by select
a want select 3 record of this table
this 3 record is 3 last news by date
i want get 3 record of end of table (3 record of end time,not of end table)
please give me a query
Posted

Here you go:

SQL
SELECT TOP 3 NewsId, NewsTitle, NewsDate FROM NEWS ORDER BY NewsDate DESC


The following orders the results so the newest are at the top:

SQL
ORDER BY NewsDate DESC


The following instructs the SELECT to get just the first 3 rows:

SQL
SELECT TOP 3
 
Share this answer
 
v2
Comments
sadegh_rusta 6-Jun-12 16:20pm    
ok,
thx
if i want get 3 record of end of table !!!!!
thatraja 6-Jun-12 16:22pm    
Try ORDER BY NewsDate ASC
sadegh_rusta 6-Jun-12 16:33pm    
ok
Maciej Los 6-Jun-12 18:31pm    
Good work, my 5!
VJ Reddy 10-Jun-12 5:04am    
Good answer. 5!
You can use a simple trick to get last 3 records in ascending order.

SQL
SELECT *
FROM (SELECT TOP 3 NewsId, NewsTitle, NewsDate FROM NEWS ORDER BY NewsDate DESC) AS DT
ORDER BY DT.NewsDate
 
Share this answer
 
Comments
VJ Reddy 6-Jun-12 19:52pm    
Nice answer. 5!
Maciej Los 7-Jun-12 3:11am    
Thank you, VJ ;)

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