Solved

Select Latest Record

Posted on 2011-09-11
6
273 Views
Last Modified: 2012-05-12
Hi all,

I think tis should be a simple one. I have a table with only 4 fields (LatestNewsID, Title, Date, Article). The LatestNewsID field is a unique field that auto increments.

In my Dreamweaver record set I have the following simple code:

SELECT *
FROM web_LatestNews

But I would like this to return just the latest record inserted into the table. i.e. the record with the largest LatestNewsID

Is this possible?

Cheers,

Tom
0
Comment
Question by:optimumreports
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 500 total points
ID: 36519830
SELECT *
FROM web_LatestNews
WHERE LatestNewsID = (SELECT MAX(LatestNewsID) FROM web_LatestNews)
0
 
LVL 1

Author Comment

by:optimumreports
ID: 36519921
Hi lludden,

Thanks - that works perfect.

Also, how would you do this to select the second highest LatestNewsID?

Cheers,

Tom
0
 
LVL 7

Expert Comment

by:XLITS
ID: 36519944
SELECT *
FROM web_latest
ORDER BY LatestNewsID DESC
LIMIT 2
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 7

Expert Comment

by:XLITS
ID: 36519948
Sorry, I had the wrong table name.

SELECT *
FROM web_latestNews
ORDER BY LatestNewsID DESC
LIMIT 2
0
 
LVL 1

Author Comment

by:optimumreports
ID: 36519993
Hi XLITS,

This just returns the last 2 records - I want just the second to last record.

Any ideas?

Tom
0
 
LVL 1

Author Closing Comment

by:optimumreports
ID: 36520003
This worked perfect and when I wanted the second to last record I just needed to add a '-1' at the end of the script:

SELECT *
FROM web_LatestNews
WHERE LatestNewsID = (SELECT MAX(LatestNewsID) FROM web_LatestNews) -1

Cheers,

Tom
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

12 Experts available now in Live!

Get 1:1 Help Now