Get the last 10 id's and ORDER BY likes

Discussion in 'MySQL' started by MyVodaFone, Aug 11, 2010.

  1. #1
    On the statement below where can I add a limit to get the last 10 id numbers from the database and from those ORDER BY likes DESC //likes is also a number

    
    $newest = mysql_query("SELECT * FROM `like` INNER JOIN (SELECT * FROM `like` GROUP BY likes DESC) s ON s.id = like.id");
    
    PHP:
    EDIT: in other words this is my statement:
    $newest = mysql_query("SELECT * FROM `like` GROUP BY id DESC LIMIT 10");
    PHP:
    ..and I want to after getting the last 10 id's, ORDER them BY likes
     
    Last edited: Aug 11, 2010
    MyVodaFone, Aug 11, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi, try this
    SELECT * FROM (SELECT * FROM `like` ORDER BY id DESC LIMIT 10) A ORDER BY likes DESC;
    Code (markup):
     
    koko5, Aug 11, 2010 IP
    MyVodaFone likes this.