升序降序

ORDER BY x ASC  -- same as default
ORDER BY x DESC  -- highest to lowest
ORDER BY lastname, firstname  -- typical name sorting; using two columns
ORDER BY submit_date DESC  -- latest first
ORDER BY submit_date DESC, id ASC  -- latest first, but fully specifying order.
  • ASC = ASCENDINGDESC = DESCENDING
  • NULLs 甚至第一次来到 DESC
  • 在上面的例子中,INDEX(x)INDEX(lastname, firstname)INDEX(submit_date) 可以显着提高性能。

但是……如上例所示,混合 ASCDESC 不能使用复合索引来获益。INDEX(submit_date DESC, id ASC) 也不会有所帮助 - “DESC”在 INDEX 声明中被语法识别,但被忽略了。