Query to retrieve latest added 3 rows?

Discussion in 'MySQL' started by Om ji Kesharwani, Oct 30, 2009.

  1. #1
    Please tell me the query to retrieve last or latest added 3 rows in mysql.
     
    Om ji Kesharwani, Oct 30, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Is there an ID or date field? You need one of the and simply sort by that field.

    SELECT fields FROM my_table ORDER BY date_column DESC LIMIT 3;

    or...

    SELECT fields FROM my_table ORDER BY id_column DESC LIMIT 3;
     
    jestep, Oct 30, 2009 IP
  3. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your reply it works...
     
    Om ji Kesharwani, Oct 30, 2009 IP
  4. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have one more question...
    I have two tables contains same id fields. I want to delete a record from both tables in single query.
    Is there any option in phpmyadmin to relate these two tables? or i have to write query?
    whatever be solution please PM.
     
    Om ji Kesharwani, Oct 30, 2009 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    doing it with query is good option for you.

    what are two tables from which you have to delete entries together?

    share table structure and we can write query for you..
     
    mastermunj, Oct 30, 2009 IP
  6. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    table 1 name = members fields: id,f_name,l_name,location
    table 2 name = paidmem fields: id,services,p_option

    Both tables have id field common
     
    Om ji Kesharwani, Oct 30, 2009 IP
  7. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #7
    following query will do the needful..

    
    "DELETE members, paidmem FROM members, paidmem WHERE members.id = '$id' AND paidmem.id = '$id'";
    
    Code (markup):
     
    mastermunj, Oct 30, 2009 IP