I remember when I started coding and writing SQL, one of the very first things I had to look up was how to order an SQL resultset by multiple columns. Let me dive right in and provide some examples…
Ordering by a single column
SELECT `col1` FROM `tablename` ORDER BY `col1`
Ordering by two columns
SELECT `col1` FROM `tablename` ORDER BY `col1`, `col2`
Ordering by two columns in different directions
SELECT `col1` FROM `tablename` ORDER BY `col1` DESC, `col2`
Follow us on Twitter
Subscribe to RSS Feed
No comments have been left yet. Be the first