Solved

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

Posted on 2011-09-25
4
211 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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now