I have a single database table that stores week entries.
Id Value WeekId 1 1.0000 1 2 2.0000 1
There can be up
You will need to add in your where clause the possibility that w2.Id is null or w3.id is null
w2.Id is null
w3.id is null
So something like
WHERE (w2.Id is null and w3.id is null) or (w3.id is null and w1.id < w2.id) or (w1.id < w2.id and w2.id < w3.id)