SQL sort sub-sets of table

Viewed 22

Given an SQL table with the following format:

ID Age
1 9
1 2
1 5
2 10
2 7
3 12

I'm trying to write a request that would return the table sorted by age within each ID, and not for the whole table. For example, the previous table should be sorted this way:

ID Age
1 2
1 5
1 9
2 7
2 10
3 12

The ages have been sorted, but only for each subset of IDs.

2 Answers

Why not:

SELECT * FROM your_table 
ORDER BY id, age

Select Id, age From tablename Order by Id, age should work

Related