Solved

Select Latest Record

Posted on 2011-09-11
6
299 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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