Alex Rivera | Logout

MySQL Sort By 2 Columns

Asked 2009-06-03T10:56:11.067
15

I have a table which holds information on television programs and I want to order it by Seasons and then by episodes. Here's a basic view of what I have:

+---+--------+---------+
|id | Season | Episode |
+---+--------+---------+
| 1 |    1   |    1    |
+---+--------+---------+
| 1 |    1   |    2    |
+---+--------+---------+
| 1 |    2   |    1    |
+---+--------+---------+
| 1 |    2   |    3    |
+---+--------+---------+

So I select what I need and order by Season. But there's going to be a lot between seasons so I need to sort episodes too, but without it affecting seasons.

Edit
Report

1 Answer

26

Do you mean:

SELECT id, Season, Episode 
FROM table 
ORDER BY Season ASC, Epsisode ASC

Sorting by multiple columns is as simple as it gets.

answered 2009-06-03T11:00:36.253

Your Answer