# Generate one table for each row of another table

**URL:** <https://community.influxdata.com/t/generate-one-table-for-each-row-of-another-table/33157>\
**Category:** Fluxlang\
**Tags:** flux, sql\
**Created:** [February 9, 2024, 10:41am UTC](https://community.influxdata.com/t/generate-one-table-for-each-row-of-another-table/33157 "2024-02-09T10:41:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brimstone](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@brimstone](https://community.influxdata.com/u/brimstone)\
**Post date:** [February 9, 2024, 10:41am UTC](https://community.influxdata.com/t/generate-one-table-for-each-row-of-another-table/33157/1 "2024-02-09T10:41:29Z")

</div>

Hi,  
I’m currently trying to solve a problem with Flux and SQL. I have a SQL Database, where I’m filtering for a specific criteria, which corresponds to multiple Sensors with a SensorID each and one or many portnumber(s). The data of the sensors is written to the InfluxDB via a Telegraf Client and identified by the SensorID and the portnumber. I already have the call to the SQL DB in Flux. Imagine the following Table as a result:

| Port | SensorID |
| --- | --- |
| 37 | 31011 |
| 38 | 31011 |
| 39 | 44522 |
| 40 | 44522 |

Now, I normally would do something like this:

```auto
from(bucket: "Sensors")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "SomeValue")
  |> filter(fn: (r) => r["SensorID"] == "31011")
  |> filter(fn: (r) => r["_field"] == "37")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

```

…but instead of the fixed values for the SensorID and the \_field (portnumber), I would like to iterate over each row of the first table and insert the values for the SensorID and \_field (portnumber) dynamically, so I can see all datastreams (in this case four) in the resulting table. Is there an easy way to achieve this?
