Click here to Skip to main content
12,951,619 members (59,663 online)
Rate this:
 
Please Sign up or sign in to vote.
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 6-Jun-12 10:09am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Here you go:

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


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

ORDER BY NewsDate DESC


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

SELECT TOP 3
  Permalink  
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
losmac 6-Jun-12 18:31pm
   
Good work, my 5!
VJ Reddy 10-Jun-12 5:04am
   
Good answer. 5!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You can use a simple trick to get last 3 records in ascending order.

SELECT *
FROM (SELECT TOP 3 NewsId, NewsTitle, NewsDate FROM NEWS ORDER BY NewsDate DESC) AS DT
ORDER BY DT.NewsDate
  Permalink  
Comments
VJ Reddy 6-Jun-12 19:52pm
   
Nice answer. 5!
losmac 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,229
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 6 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100