[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

Select Latest Record

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
optimumreports
Asked:
optimumreports
  • 3
  • 2
1 Solution
 
lluddenCommented:
SELECT *
FROM web_LatestNews
WHERE LatestNewsID = (SELECT MAX(LatestNewsID) FROM web_LatestNews)
0
 
optimumreportsAuthor Commented:
Hi lludden,

Thanks - that works perfect.

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

Cheers,

Tom
0
 
XLITSCommented:
SELECT *
FROM web_latest
ORDER BY LatestNewsID DESC
LIMIT 2
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
XLITSCommented:
Sorry, I had the wrong table name.

SELECT *
FROM web_latestNews
ORDER BY LatestNewsID DESC
LIMIT 2
0
 
optimumreportsAuthor Commented:
Hi XLITS,

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

Any ideas?

Tom
0
 
optimumreportsAuthor Commented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now