Simon Slavin on Friday, April 26, 2019 10:50 AM wrote...
>On 26 Apr 2019, at 3:30pm, Jose Isaias Cabrera <jic...@outlook.com> wrote:

>Once you have defined those indices, execute the ANALZE command, then try
>the .expert again.
Thanks.

>What led to you using WHERE 1=1 ?  An apparent bug ?
Long story. The app has many textboxes where the user can insert a string and 
hit ENTER and so a search is added to the query based on the textboxes that 
have data in them.  So, having WHERE 1=1 makes it easy to have other search 
additions by just doing,

AND (a.field_A LIKE %jic%)

and adding another one,

AND (b.field_B LIKE %something%)

etc., etc. So, in the end the query ends up being something like this,

 SELECT a.*,sum(b.AnnualDossier) as Dossier FROM Project_List AS a
 LEFT JOIN Project_ABT_Budget AS b ON a.ProjID = b.ProjID
 AND
 b.InsertDate =
 (SELECT MAX(InsertDate) FROM Project_ABT_Budget WHERE b.ProjID = ProjID)
 WHERE a.ProjID IN
 (
 SELECT a.ProjID FROM Project_List WHERE 1=1
 AND lower(a.Manager) LIKE '%diggs%'
 AND (a.field_A LIKE %jic%)
 AND (a.field_B LIKE %something%)
 ) AND a.InsertDate =
(SELECT MAX(InsertDate) FROM Project_List WHERE ProjID = a.ProjID)

 GROUP BY a.ProjID;

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to