Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to select only the single, most recent data record?

Posted on 2011-09-25
4
Medium Priority
?
232 Views
Last Modified: 2012-05-12
ColdFusion 9
SQL Server 2005

I need to query a data table and get back only the single, most recent data record. How can I do that?

<cfquery name="getmostrecentblogpost" datasource="#application.datasource#">
SELECT blogID, blogTitle, blogExcerpt, blogAuthor, blogDate
FROM TIRBlog
WHERE blogDate (is the most recent date)
</cfquery>

Open in new window


I've looked around, but no solution seems to exactly fit my requirement. Thank you as always.

Eric
0
Comment
Question by:Eric Bourland
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
sajayc earned 2000 total points
ID: 36596584
Hi,
You can modify your query so that the results are in date order with most recent first and then use the top 1 to only return 1 record.

SELECT top 1 blogID, blogTitle, blogExcerpt, blogAuthor, blogDate
FROM TIRBlog
order by blogDate

Does that do what you want?
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 36596586
I'll try that! hang on....
0
 
LVL 3

Author Closing Comment

by:Eric Bourland
ID: 36596594
That worked very well. Thank you,sajayc.
0
 
LVL 3

Expert Comment

by:sajayc
ID: 36596597
Your welcome!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question