SQL order by two columns & loop
+----------+---------+
| Category | id |
+----------+---------+
| 1 | 70 |
| 1 | 71 |
| 3 | 80 |
| 4 | 73 |
| 5 | 83 |
| 5 | 81 |
| 5 | 69 |
| 4 | 72 |
| 1 | 74 |
| 4 | 82 |
| 3 | 85 |
| 3 | 68 |
| 4 | 88 |
| 6 | 66 |
+----------+---------+
I have the following table, and need a way of producing results which will involve an SQL statement with a loop, but i'm not sure how.
First I want to take out the results in order of category, so 1, 3, 4, 5, 6, and for each of those categories, order the records by id, (category/id 1/70, 1/71, 1/74, 3/68, 3/80, 3/85, 4/72, 4/73, 4/88 etc...).
When there are no more records to show, I want to loop back to the first smallest category and ID number.
How is this possible? Note that the categories do not ascend by +1 every time, so it is not possible to take the previous category number and +1.
Thanks in advance.
Izzy
