For example I have this table:
TableX:
code name consecutive
0 a 0
2 b 1
3 c 2
1 d 3
5 e 0
4 f 1
6 g 2
7 h 0
9 i 1
10 j 2
8 k 3
I want to do this:
code name consecutive
(0,2,3,1) (a,b,c,d,e) (0,1,2,3)
(5,4,6) (e,f,g) (0,1,2)
(7,9,10) (h,i,j) (0,1,2)
(8) (k) (3)
SQL has no concept of “consecutive” in that sense. You’d have to define the grouping in your data model somewhere. There’s nothing to say that your table wouldn’t actually be stored in a different order like:
If you want to specify ordering in a table, it can’t rely on the “proximity” of other records because the way SQL databases store records is not in a consecutive structure like that at all behind the scenes.