MYSQL Select from table, get newest/last 10 rows in table

后端 未结 4 1621
礼貌的吻别
礼貌的吻别 2021-02-04 09:50

What\'s the best, and easiest way to do this? My query currently is:

  SELECT * 
    FROM chat 
   WHERE (userID = $session AND toID = $friendID) 
      OR (use         


        
4条回答
  •  盖世英雄少女心
    2021-02-04 10:13

    to reverse the order (therefore get last 10 instead of first 10), use DESC instead of ASC

    EDIT

    Based on your comment:

    SELECT * FROM (
      SELECT * 
      FROM chat 
      WHERE (userID = $session AND toID = $friendID) 
        OR (userID = $friendID AND toID = $session)  
      ORDER BY id DESC
      LIMIT 10
    ) AS `table` ORDER by id ASC
    

提交回复
热议问题