|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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= |
|
#2
|
|||
|
|||
|
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? |
|
#3
|
|||
|
|||
|
____
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????? |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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).] |
|
#6
|
|||
|
|||
|
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? |
|
#7
|
|||
|
|||
|
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= |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Selecting last inserted row |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|