Fetch data from table with condition in other table

Hello everyone, I need to create a query for grafana using the Flux language (fortunately my grafana on home assistant supports it … I have already configured the datasource in Flux mode instead of InfluxQL). The peculiarity of this query is that it must take data from a table only in the time range in which in another table the value “state” is = 1. Is it possible? suppose I want to collect the “value” values from the “consumption” table only when the “state” in the “dhw” table = 1. Can you help me? Keep in mind that in the state tables, I only have the values when they are different from the previous one. Eg. If you are at 2:00 pm it is = 1 and at 4:00 pm = 0. I only have two entries, one at 2pm and one at 4pm.
Thanks a lot to everyone

Hello @TheMiloNet,
So essentially you’re looking to perform a left or right join?