Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Select last entered record in table
Old 11-13-2004, 08:12 PM Select last entered record in table
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Hey,

I have a section on my site for news articles. On the home page, it displays the latest article from the database.

The SQL that powers this is simply:

Code:
SELECT * FROM tbl_News ORDER BY nws_Date DESC
The code then just picks the record that the pointer is currently on, and displays it.

What I was wondering, is if there's a way to only select the last entered record in the DB, so that the SQL Statement doesn't return the entire table, which could be a significant performance hit once more than a few news articles have been added?
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
 
Register now for full access!
Old 11-13-2004, 10:12 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
you could do this:
Code:
SELECT TOP 1 * FROM tbl_News ORDER BY nws_Date DESC
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 11-14-2004, 08:12 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
That works great, thanks!
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 11-14-2004, 08:13 AM
vivekar's Avatar
Webmaster Talker

Posts: 612
Trades: 0
To know the last record id when you are inserting a new row, use

Code:
SELECT @@identity
Also read the @@identity crisis
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Old 11-14-2004, 12:10 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
That only works with SQL Server and is not what Minaki is looking for. It is, however, a great tip that people tend not to know.
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 11-14-2004, 06:53 PM
vivekar's Avatar
Webmaster Talker

Posts: 612
Trades: 0
It works with MSAccess too.
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Old 11-14-2004, 07:19 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
Oh it does? My mistake, thank you for correcting me.
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 11-15-2004, 05:18 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Actually... I was using a less effective way of getting that value and was about to ask if there was a better way of doing so...
Thanks again!
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Reply     « Reply to Select last entered record in table
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31227 seconds with 12 queries