1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to get the last 5 entries from a mysql table?

Discussion in 'MySQL' started by kuser, May 18, 2012.

  1. #1
    I have an mysql table containg some important notes.

    the problem is this: SQL it's not always writing always the last entry at the end of the table, if a free "cell" is found it will write the new entry even in the middle of the table.

    So, is there anyway i can extract the last 5 entered data?

    I store the "entered date" but, i have over 300,000 entries so far... and i will just slow down the database by parsing it all again and again for the "last 5 entries" ...
     
    kuser, May 18, 2012 IP
  2. kulik

    kulik Member

    Messages:
    162
    Likes Received:
    18
    Best Answers:
    1
    Trophy Points:
    45
    #2
    Either do it by date added or ID number. Then...

    SELECT * FROM `your_table` LIMIT 0, 5

    And ORDER BY if needed. Google it if you don't understand.
     
    kulik, May 18, 2012 IP
  3. kuser

    kuser Banned

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Code (Text):
    1.  
    2. "SELECT * FROM comments LIMIT 0,5 [B]ORDER BY 'article_id' DESC[/B]"
    3.  
    What it's wrong?
     
    kuser, May 18, 2012 IP
  4. TeemuGr

    TeemuGr Greenhorn

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    Try:


    SELECT * FROM comments ORDER BY article_id DESC LIMIT 0,5
     
    TeemuGr, May 23, 2012 IP