Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL SQL-Server-2008 Data query , +
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 at 6-Jun-12 16:20pm
   
ok,
thx
if i want get 3 record of end of table !!!!!
thatraja at 6-Jun-12 16:22pm
   
Try ORDER BY NewsDate ASC
sadegh_rusta at 6-Jun-12 16:33pm
   
ok
losmac at 6-Jun-12 18:31pm
   
Good work, my 5!
VJ Reddy at 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 at 6-Jun-12 19:52pm
   
Nice answer. 5!
losmac at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 6 Jun 2012
Copyright © CodeProject, 1999-2014
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