SQLite Forum

ORDER BY not ordering with the correct result
Login
>So this is your query (reformatted for eye-bleeding prevention):

Thanks for the rearranging.  Much cleaner and easier to the eyes. :-)

[clip]

>b.InsertDate = (b.InsertDate is NULL)
>
>What is the "intention" of this code as it seems somewhat confusing? 

This is because if there are no result from total(b.AnnualDossier), in other words, the ProjID does not exists in the table b (ABT_Budget), then that record won't show in the result.  So, with this assignment, the result has all the records listed in the WITH part of the code.

>Of course, if what you mean is that you want b.InsertDate to be the max(InsertDate) for that project (as in correlated) then it should be b.InsertDate = (select max(insertdate) from abt_budget where ProjId = b.ProjID).

Yes, you're right. Thanks. I found out what it was not sorting (spaces in front the data). But, this is also much faster by using your suggested changes.