Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting the latest entry

Status
Not open for further replies.

rastkocvetkovic

Programmer
Aug 11, 2002
63
SI
How could I output the latest news by entry's id (news.id, which is autonumber)?
Is that performed by SELECT MAX(id) FROM news?
How can I stick that into the code.

Please help. Thanks in advance
 


Make the query something like this.

sql="select * from news order by id desc"
It will give you all the records with the latest record first.

Hope it helps you.


*********************
Sincerery rdsmadhu.
*********************
 
'# set up db for connection..
strSQL = "SELECT Max(newsID) FROM news"

'# Execute it...

'# Put max id in string:
maxID = rs.Fields(0)

'# Close db up...

'# set it up again..
strSQL2 = "SELECT * FROM news WHERE newsID=" & maxID

'# print your news..
'# close it up.

www.vzio.com
ASP WEB DEVELOPMENT



 
actully, you can use what he said, and then if you only want to show the last record do this:

sql="select * from news order by id desc LIMIT 1" www.vzio.com
ASP WEB DEVELOPMENT



 
Woohoo. Nice how you helped - all solutions seem to work. And I also found another one:
SELECT * FROM News WHERE id = (SELECT MAX(id) FROM News )

It selects the news with max id. Neat!
 
Note: limit keyword is (to my knowledge) only for MySQL. codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
You're not a complete programmer unless you know how to guess.
I hope I never consider myself an 'expert'.
<insert witticism here>
 
why not use the TOP command??

sql = &quot;SELECT TOP 5 * FROM News ORDER BY id DESC&quot;

The best way to get what you want without doing a lot of extra steps.

Cheers,

Gorkem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top