SQLite Forum

Missing records from the IN list
Login
Greetings.

The following query is missing 3 records.  I know that it's probably because the LEFT JOIN does not have those records, but I have added a COALESCE to arrange for those missing records.  Any ideas how to get this to work?

```
SELECT a.ProjID, COALESCE(sum(b.AnnualDossier), 0.00) AS Dossier FROM Project_List AS a 
LEFT JOIN ABT_Budget AS b ON a.ProjID = b.ProjID
AND
(
   b.InsertDate = 
   (
       SELECT MAX(InsertDate) FROM ABT_Budget WHERE b.ProjID = ProjID
   )
   OR
       b.InsertDate IS Null
)
WHERE a.ProjID IN 
(
   SELECT ProjID FROM Project_List WHERE 1=1 
  AND
  (
     a.ProjID IN ('PR0000019149','PR0000018256','PR0000018262','PR0000019185','PR0000019187')
  )  
  AND InsertDate = 
  ( 
     SELECT MAX(InsertDate) FROM Project_List WHERE 1=1 
     AND 
     (
        a.ProjID IN ('PR0000019149','PR0000018256','PR0000018262','PR0000019185','PR0000019187')
     )   
  ) 
)
AND a.InsertDate = 
      (SELECT MAX(InsertDate) FROM Project_List WHERE ProjID = a.ProjID) 
  GROUP BY a.ProjID;

PR0000018256|0.0
PR0000018262|0.0
sqlite>
```

Thanks for your support.

josé