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

后端 未结 4 1627
礼貌的吻别
礼貌的吻别 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:28

    First select the last 10 from the table, then re-order them in ascending order.

    SELECT * FROM (SELECT * FROM table ORDER BY id DESC LIMIT 10) sub ORDER BY id ASC
    

提交回复
热议问题