I have two tables 1. Person and 2. Children
CREATE TABLE Persons (
PersonID int,
Name varchar(255)
);
CREATE TABLE Children (
ChildID int,
PersonID int,
Name varchar(255),
DOB Date);
I combined them with left join.
select
person.PersonID
, person.Name
, child.childID
, Child.DOB
FROM(
select PersonID
, Name
From Persons
) as person
left join (
select ChildID
, PersonID
, Name
, DOB
From Children
Order By DOB ASC
) as child
on child.PersonID = person.PersonID
The result show how children a person has with their date of birth. Till then this is fine. What I want Person will be ordered by ascending with their ID and children list will be ordered by their date of birth in ascending order. But it seems that children are coming in random order. I tried to order by on the result but that does not serve my purpose. I want PersonID ascending order and children list of each person will be ordered by their date of birth ascending.
Here is the link http://sqlfiddle.com/#!9/b56f95/3 of the table and query I performed.