0

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.

BeRT2me
  • 12,699
  • 2
  • 13
  • 31
Guillaume
  • 449
  • 3
  • 14
  • Do you have two questions here? Are you first wondering how to return a subset of data? Then how to sort those results? Or rather, are you wanting to return ALL rows, but then sort only a few of them? If the latter, then please provide more sample data and expected outcome. – Isolated Sep 20 '22 at 17:40

2 Answers2

0

Why not:

SELECT * FROM your_table 
ORDER BY id, age
Jino Michel Aque
  • 513
  • 1
  • 4
  • 16
-1

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

Joe
  • 147
  • 1
  • 8