#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Crestline, CA. USA
    Posts
    9
    Rep 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=
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    4
    Rep 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?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    19
    Rep 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?????

  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Crestline, CA. USA
    Posts
    9
    Rep 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).]
  10. #6
  11. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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?
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Crestline, CA. USA
    Posts
    9
    Rep 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=

Similar Threads

  1. div style="overflow: scroll;"
    By slydero in forum HTML Programming
    Replies: 8
    Last Post: October 26th, 2004, 10:54 AM
  2. SELECTing the 'middle' row in a table
    By C3P0 in forum MySQL Help
    Replies: 4
    Last Post: November 12th, 2003, 03:22 PM
  3. <THEAD> not printing across multiple pages
    By allanmcc in forum HTML Programming
    Replies: 2
    Last Post: September 29th, 2003, 09:47 PM
  4. returning data from a row inserted using auto_increment
    By dannywild82 in forum MySQL Help
    Replies: 3
    Last Post: August 28th, 2003, 04:36 PM

IMN logo majestic logo threadwatch logo seochat tools logo