MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 5th, 2000, 08:50 PM
Cougar Cougar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: Crestline, CA. USA
Posts: 9 Cougar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have an application that inserts a row of data into a table every 5 minutes.

From a different machine, I like to be able to select the last inserted row.

Any Suggestions? (auto_increment doesn't work for this applications.)

Thanks.

------------------
=Don=

Reply With Quote
  #2  
Old September 6th, 2000, 01:18 AM
ilya ilya is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Posts: 4 ilya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This might not be good way to select the latest row inserted, but I've used

"SELECT * FROM table ORDER BY id DESC LIMIT 1"

Anything wrong with doing it this way?

Reply With Quote
  #3  
Old September 6th, 2000, 06:07 AM
kudinov kudinov is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 19 kudinov User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
____
auto_increment doesn't work for this
- Modify table, add a field for storing of DATETIME or check the current structure of table.
_____
"SELECT * FROM table ORDER BY id DESC LIMIT 1"
- It can fail (at least in Oracle) if there was deletion of some rows from [table] before.

Is it right in MySQL?????


Reply With Quote
  #4  
Old September 6th, 2000, 09:33 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
Yes it'll work as MySQL increments the largest id to generate the next id, meaning that deleted items will not be replaced.

However, I agree that it's not a good idea. That functionality might change in the future. Better to add a datetime field and use it.

Reply With Quote
  #5  
Old September 6th, 2000, 12:31 PM
Cougar Cougar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: Crestline, CA. USA
Posts: 9 Cougar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks Guys! That's just what I needed. There is a time stamp in the table, but it's a string version. ("2000-08-28 14:55:00") so I had in place a real ugly solution. But this is what I really needed.

Thanks again.

------------------
=Don=

[This message has been edited by Cougar (edited September 06, 2000).]

Reply With Quote
  #6  
Old September 6th, 2000, 01:00 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
If you want the non-string version of any mysql date/time data type, just add +0 in your select:

select datetimefield+0

But that shouldn't matter for a sort, or are you using a char field to store the date rather than one of the built in types?

Reply With Quote
  #7  
Old September 6th, 2000, 05:23 PM
Cougar Cougar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: Crestline, CA. USA
Posts: 9 Cougar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Wow, didn't know that either. The application that inserts the data is a prefab app, came with the device. But they did use a 'datetime' type, so your +0 suggestion also works.

Thanks again.

------------------
=Don=

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Selecting last inserted row


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT