Add a column to the query which can sub identify the data to sort on that.
In the below example I use a Common Table Expression with the selects what you showed and places them into specific groups on the CTE; then do a union
off of both of those groups into AllStudents
.
The final select will then sort AllStudents
by the SortIndex
column first and then by the name
such as:
WITH Juveniles as
(
Select 1 as [SortIndex], id,name,age From Student
Where age < 15
),
AStudents as
(
Select 2 as [SortIndex], id,name,age From Student
Where Name like "%a%"
),
AllStudents as
(
select * from Juveniles
union
select * from AStudents
)
select * from AllStudents
sort by [SortIndex], name;
To summarize, it will get all the students which will be sorted by group first, and subsorted by the name within the group after that.