[firebird-support] avoid query subselect

2019-07-19 Thread 'Mr. John' mr_joh...@yahoo.com [firebird-support]
HiI have a performance issue on a query where I need all parent record and from child table I only want a flag if there is any child record matching a condition,so I write something like that: SELECT P.ID,IIF(SUB.ID IS NULL,0,1) AS ISDATA  FROM PARENT P   LEFT JOIN     (SELECT FIRST 1 PA.ID FROM

Re: [firebird-support] avoid query subselect

2019-07-19 Thread liviuslivius liviusliv...@poczta.onet.pl [firebird-support]
Hi,   i suppose this one is much faster   SELECT P.ID , CASE WHEN EXISTS(SELECT * FROM  CHILD C WHERE C.ID_PARENT=P.ID AND C.MYFIELD=3)   )  THEN 1 ELSE 0 END AS ISDATA   FROM PARENT P INNER JOIN TABLE3 T3 ON P.ID=T3. INNER JOIN TABLE3 T4 ON P.ID=T4. ...     Regards, K

Re: [firebird-support] avoid query subselect

2019-07-19 Thread 'Mr. John' mr_joh...@yahoo.com [firebird-support]
indeed much better thanks! On Friday, July 19, 2019, 02:34:20 PM GMT+3, liviuslivius liviusliv...@poczta.onet.pl [firebird-support] wrote:   Hi, i suppose this one is much faster SELECT P.ID, CASE WHEN EXISTS(SELECT *  FROM  CHILD C WHERE C.ID_PARENT=P.ID AND C.MYFIELD=3) ) THEN