SQLite Forum

Error: no such column: x
Login
What do you mean "no such column"?  I do not see any such error message ...

If you mean why is the result of the correlated subquery NULL, that is because there are no rows that satisfy the subquery, or they all have a NULL InsertDate.

Similarly, pl_insert may be NULL if all the InsertDate for that projID in Project_List are NULL.

While this may *appear* distressing it is not.  It would be more work to get rid of the nulls than to leave them be.  Plus, of course, the outer query (shown at the top) uses the *equal* (==) in the constraints involving these columns, and there is no value (not even another NULL) that *equals* (==) a NULL.  In other words, there is no way to *descend* into the other tables from a NULL value, so they (ought to be culled) very quickly during execution anyway.

Perhaps you could use the following instead (which may be faster anyway):

```
with maxes (ProjID, pl_insert, ab_insert)
  as (
      select ProjID,
             pl_insert,
             ab_insert
        from (
                select ProjID,
                       (select max(InsertDate) from Project_List where ProjID == o.ProjID) as pl_insert,
                       (select max(InsertDate) from ABT_Budget where ProjID == o.ProjID) as ab_insert
                  from (
                        select distinct ProjID
                          from Project_List
                       ) as o
             )
       where ProjID is not null
         and pl_insert is not null
         and ab_insert is not null
     )
select *
  from maxes
;
```