# Is there a way to "select from select" in table\_query?

**URL:** https://discuss.tryton.org/t/is-there-a-way-to-select-from-select-in-table-query/7292
**Category:** Developer
**Tags:** python-sql
**Created:** [May 18, 2024, 8:54am UTC](https://discuss.tryton.org/t/is-there-a-way-to-select-from-select-in-table-query/7292 "2024-05-18T08:54:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![lb1975](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@lb1975](https://discuss.tryton.org/u/lb1975)
#### Post date: [May 18, 2024, 8:54am UTC](https://discuss.tryton.org/t/is-there-a-way-to-select-from-select-in-table-query/7292/1 "2024-05-18T08:54:03Z")

</div>

Hi,

I’m wondering if it’s possible by code to replicate the SQL syntax in table\_query def:  
“select tt.id from (select id as id from table t) tt”  
and where I can find an example ?

Tks in advance,  
Laurent

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [May 18, 2024, 9:56am UTC](https://discuss.tryton.org/t/is-there-a-way-to-select-from-select-in-table-query/7292/2 "2024-05-18T09:56:32Z")

</div>

See the [“Select with sub-select” in the python-sql examples](https://foss.heptapod.net/tryton/python-sql).  
This is because the `SelectQuery` object is a subclass of `FromItem` object.

---

<div class="post-metadata">

### Author: ![lb1975](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@lb1975](https://discuss.tryton.org/u/lb1975)
#### Post date: [May 29, 2024, 7:29am UTC](https://discuss.tryton.org/t/is-there-a-way-to-select-from-select-in-table-query/7292/3 "2024-05-29T07:29:58Z")

</div>

In fact I realise that what I need is more a “having” instruction to a group\_by select for instance :  
select sum(quantity) from table group\_by product having sum(quantity) \> 0  
I don’t find the having instruction in python-sql but is it possible to put the select without the having condition in a table variable and select the element \> 0 in this table ?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [May 29, 2024, 7:34am UTC](https://discuss.tryton.org/t/is-there-a-way-to-select-from-select-in-table-query/7292/4 "2024-05-29T07:34:29Z")

</div>

> [@lb1975](#):
>
> I don’t find the having instruction in python-sql

python-sql supports `having` clause on `Select` query.  
The example in the README are not exhaustif but you can assume that all SQL standard features (especially the very common) are in python-sql.

---

<div class="post-metadata">

### Author: ![lb1975](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@lb1975](https://discuss.tryton.org/u/lb1975)
#### Post date: [May 29, 2024, 7:41am UTC](https://discuss.tryton.org/t/is-there-a-way-to-select-from-select-in-table-query/7292/5 "2024-05-29T07:41:41Z")

</div>

Ok great I try it tks Cedric
