3

I have the follow SQL query statement:

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

Can you please tell how can I specify query sort order?

Thank you.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
michael
  • 99,904
  • 114
  • 238
  • 340

3 Answers3

14

It's actually quite easy. Here's an example to sort your query by the "subject":

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

This will order your list A-Z. If you want to order your list Z-A then use:

ORDER BY subject DESC
Tim Cooper
  • 151,519
  • 37
  • 317
  • 271
Andrew Ellis
  • 1,051
  • 12
  • 29
1

Use the "ORDER BY"

For more information check out w3schools

ChickSentMeHighE
  • 1,716
  • 5
  • 21
  • 29
0

this works:

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

but i wouldn't mind taking off the 'asc' at the end being that ASC is true by default.

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

rink.attendant.6
  • 40,889
  • 58
  • 100
  • 149
Elisha
  • 1
  • 1