开发者

SortBy for one-to-many relationship

I have a two tables which are linked by a one-to-many relationship. Now I need to sort the rows based on the key which I have in my first table.

For Ex

TeacherID    StudentID
  1               1
  1               2
  1               3
  1               4
  1               5
  1               6
  1               7
  1               8
  2               9
  2               10
  2     开发者_如何学JAVA          11
  2               12

If I sort the Rows based on by teacherID, the student id's are changing for each and every execution.

In the result set the studentID are changing in the random order. Now I need the studentID's not to be changed.

Is there anything I can do, to solve this problem without using sort by the studentID column.


You can sort on both.

ORDER BY
  TeacherID, StudentID

Selecting data from any database engine without specifying an ORDER BY doesn't guarantee any order at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜