?
Solved

Select Latest Record

Posted on 2011-09-11
6
Medium Priority
?
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 2000 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

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 …
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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