Solved

Select Latest Record

Posted on 2011-09-11
6
291 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dreamweaver CS6 FTP issues 12 1,308
dreamweaver cs6 keep getting error 2 msg 16 393
slide show not working correctly 10 414
What is needed to center a flash image to the center of the page? 4 100
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…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 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