# Get all records inside time intervals given by another stream of tables

**URL:** <https://community.influxdata.com/t/get-all-records-inside-time-intervals-given-by-another-stream-of-tables/28550>\
**Category:** Fluxlang\
**Tags:** flux\
**Created:** [February 10, 2023, 4:22pm UTC](https://community.influxdata.com/t/get-all-records-inside-time-intervals-given-by-another-stream-of-tables/28550 "2023-02-10T16:22:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kratheon](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@Kratheon](https://community.influxdata.com/u/Kratheon)\
**Post date:** [February 10, 2023, 4:22pm UTC](https://community.influxdata.com/t/get-all-records-inside-time-intervals-given-by-another-stream-of-tables/28550/1 "2023-02-10T16:22:38Z")

</div>

Hello there !

I’m new quite new in InfluxDB and I wanted to know how to do a query in flux.  
In that query, let’s say there is some specifications :

- The bucket is named ‘ **TestBucket** ’
- In this bucket, there is 2 measurements : **‘M1’** and **‘M2’**.
- I’m targetting a time range from **‘T1’** to **‘T2’** for both measurements.
- Both measurements have records with **integer** values.

The goal to this query is to returns all the records of **M1** during the same intervals where the average value of **M2** ’s records are less than **50** , for every 3s intervals.

I tried something like this but I only have the M1’s records that matches the end time of each M2’s interval…

> import “join”
> 
> left =  
> from(bucket: “TestBucket”)  
> |\> range(start: T1, stop : T2)  
> |\> filter(fn: (r) =\> r[“\_measurement”] == “M2”)  
> |\> aggregateWindow(every: 3s, fn: mean, createEmpty: false)  
> |\> filter(fn: (r) =\> r.\_value \< 50)  
> |\> group(columns: [“\_time”])  
> //|\> yield(name: “LEFT”)
> 
> right =  
> from(bucket: “TestBucket”)  
> |\> range(start: T1, stop : T2)  
> |\> filter(fn: (r) =\> r[“\_measurement”] == “M1”)  
> |\> group(columns: [“\_time”])  
> //|\> yield(name: “RIGHT”)
> 
> result = join.inner(  
> left: left,  
> right: right,  
> on: (l, r) =\> l.\_time == r.\_time,  
> as: (l, r) =\> ({r with}),  
> )  
> |\> group()  
> |\> yield(name: “RESULT”)

How could I resolve my goal ?

Tank you all for your answers 😀
