Page 1 of 1

QBSelect: FROM part as a select

PostPosted: Thu Jun 28, 2018 9:56 am
by rieder
Hi

Is it possible to translate an SQL statement with a sub select in the FROM part into a Query Builder statement? Like:

Code: Select all
select sum(personsId)
from (
    select id as personsId
    from persons
    where id > 1000
    and id < 1200) xxx


Thanks for help.
Kind regards.

Re: QBSelect: FROM part as a select

PostPosted: Thu Jun 28, 2018 10:08 am
by mboegem
Hi Birgit,

if you lookup the QBResult node in solution explorer, you'll find the addSubSelect function.
This will take either a query with optional args OR another QBSelect as parameters.

Hope this helps.

Re: QBSelect: FROM part as a select

PostPosted: Thu Jun 28, 2018 10:30 am
by rieder
Hi Marc

Thank you for the answer.
Actually, I was looking for a query in the from clause. Not in the result.
But anyway, I'll try to rewrite the sql to use the query in the result. I guess, from is not possible.

Best regards

Re: QBSelect: FROM part as a select

PostPosted: Thu Jun 28, 2018 12:26 pm
by mboegem
rieder wrote:Actually, I was looking for a query in the from clause. Not in the result.

Yes, sorry... was more leaded by 'subSelect' option than the actual place.

I guess you can use the 'exists' function from the QBSelect node for this.

Re: QBSelect: FROM part as a select

PostPosted: Thu Jun 28, 2018 2:52 pm
by rieder
Thank you. Was nice to «hear» from you :-)