tags:

views:

144

answers:

2

I have a table which holds information on television programs and I want to order it by Seasons and then by episodes. Heres 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 theres going to be alot between seasons so I need to sort episodes too but without it effecting seasons. Do you know what I mean? Its hard to explain :p

+2  A: 

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 - but your heading "MySQL Sort By 2 Tables" is quite misleading.

Stefan Gehrig
Yes I meant columns. Im too tired to use the right terminolagy :p
Ben Shelock
+1  A: 

We know what you mean :) In your order by you should have

ORDER BY Season, Episode

It will sort by Season and then on Episode within Season

Rashmi Pandit