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
  • 732,580
  • 175
  • 1,330
  • 1,459
michael
  • 106,540
  • 116
  • 246
  • 346

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
Andrew Ellis
  • 1,175
  • 1
  • 12
  • 29
1

Use the "ORDER BY"

For more information check out w3schools

ChickSentMeHighE
  • 1,706
  • 6
  • 21
  • 30
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
  • 44,500
  • 61
  • 101
  • 156
Elisha
  • 1
  • 1