# QBSelect: FROM part as a select

**URL:** <https://forum.servoy.com/t/qbselect-from-part-as-a-select/19734>\
**Category:** Classic Servoy\
**Created:** [June 28, 2018, 7:56am UTC](https://forum.servoy.com/t/qbselect-from-part-as-a-select/19734 "2018-06-28T07:56:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rieder](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rieder/32/4950_2.png) [@rieder](https://forum.servoy.com/u/rieder)\
**Post date:** [June 28, 2018, 7:56am UTC](https://forum.servoy.com/t/qbselect-from-part-as-a-select/19734/1 "2018-06-28T07:56:39Z")

</div>

Hi

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

```auto
select sum(personsId)
from (
    select id as personsId
    from persons 
    where id > 1000 
    and id < 1200) xxx

```

Thanks for help.  
Kind regards.

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [June 28, 2018, 8:08am UTC](https://forum.servoy.com/t/qbselect-from-part-as-a-select/19734/2 "2018-06-28T08:08:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rieder](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rieder/32/4950_2.png) [@rieder](https://forum.servoy.com/u/rieder)\
**Post date:** [June 28, 2018, 8:30am UTC](https://forum.servoy.com/t/qbselect-from-part-as-a-select/19734/3 "2018-06-28T08:30:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [June 28, 2018, 10:26am UTC](https://forum.servoy.com/t/qbselect-from-part-as-a-select/19734/4 "2018-06-28T10:26:10Z")

</div>

> rieder:  
> 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.

---

<div class="post-metadata">

**Author:** ![rieder](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rieder/32/4950_2.png) [@rieder](https://forum.servoy.com/u/rieder)\
**Post date:** [June 28, 2018, 12:52pm UTC](https://forum.servoy.com/t/qbselect-from-part-as-a-select/19734/5 "2018-06-28T12:52:59Z")

</div>

Thank you. Was nice to «hear» from you ![:-)]( "Smile")
