如何在sql查询中指定sql排序顺序

时间:2010-07-21 16:41:20

标签: sql

我有以下SQL查询语句:

SELECT subject, sender_list, date, uid
FROM messages
WHERE folder_id = 3

请告诉我如何指定查询排序顺序?

谢谢。

3 个答案:

答案 0 :(得分:12)

实际上很容易。以下是按“主题”对查询进行排序的示例:

SELECT subject, sender_list, date, uid
  FROM messages
 WHERE folder_id = 3
 ORDER BY subject ASC

这将订购您的清单A-Z。如果您想订购Z-A清单,请使用:

ORDER BY subject DESC

答案 1 :(得分:1)

使用“ORDER BY”

有关详细信息,请查看w3schools

答案 2 :(得分:0)

这有效:

SELECT subject, sender_list, date, uid
  FROM messages
 WHERE folder_id = 3
 ORDER BY subject ASC

但是我不介意最后将“ asc”取消,因为默认情况下ASC为true。

https://www.w3schools.com/sql/sql_orderby.asp