# Influxdb Query - Confusion

**URL:** <https://discourse.nodered.org/t/influxdb-query-confusion/11520>\
**Category:** General\
**Created:** [24 May 2019 23:15 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520 "2019-05-24T23:15:44Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [24 May 2019 23:15 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/1 "2019-05-24T23:15:44Z")

</div>

Hi

I’m writing Energy readings to an influxdb datasource and i’d like to do check/search/lookup for some values that will have been posted, but I can’t seem to get other query commands to work.

FYI - The server config is 192.168.1.222:8086/energy and I can confirm the following works

```auto
select * from Watts;

```

However these others attempted to search for the largest value ever written, plus many more don’t. ☹ what am I missing ?

```auto
select MAX "value" FROM "Watts";
select MAX * FROM Watts;

```

I’ve tried to work things out from influx, (below), but no joy there either..

[https://docs.influxdata.com/influxdb/v1.7/query\_language/functions/#max](https://docs.influxdata.com/influxdb/v1.7/query_language/functions/#max)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 May 2019 23:39 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/2 "2019-05-24T23:39:44Z")

</div>

My guess is that you are use to sql syntax...right? (me too, I've just started using influx)

try `select max(value) from watts` no quotes

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [25 May 2019 00:17 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/3 "2019-05-25T00:17:07Z")

</div>

I strongly recommend installing Grafana which will give you a graphical query interface. You can then see the actual queries it produces and you can then use them for yourself.

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [25 May 2019 08:42 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/4 "2019-05-25T08:42:13Z")

</div>

Hi @TotallyInformation

I already do have Grafana installed, but I’m still getting to grips with its query interface, and the Node Red approach for something quite basic seemed like it would be easier (at least that’s what I thought 🤣)

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [25 May 2019 08:45 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/5 "2019-05-25T08:45:29Z")

</div>

Thanks @zenofmud

> [@zenofmud](#):
>
> select max(value) from watts

This query does not give me an error but it only returns an [Empty] response ? No value is shown ?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [25 May 2019 09:04 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/6 "2019-05-25T09:04:28Z")

</div>

😉

Yes, the downside of InfluxDB is that its query language is _close_ to but not the same as SQL. ☹

You need:

```auto
SELECT max("value") FROM "watts"

```

Note also that the FROM clause may need prefixing with a database name and/or a retention policy name.

If that isn't working, we would need to see more about the structure of your database.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 May 2019 09:04 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/7 "2019-05-25T09:04:43Z")

</div>

Hmm now I have learned something but I'm not suer what. In the cli fro influx I thought using quotes didn't work. I have to go try again. 😕

In the cli I'd use `show measurments` to see the rows names.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 May 2019 09:15 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/8 "2019-05-25T09:15:06Z")

</div>

interesting, you can use or not use the quotes;

```auto
> select max("value") from "test"
name: test
time max
---- ---
1558443386066743407 9.968976471022282
> select max(value) from test
name: test
time max
---- ---
1558443386066743407 9.968976471022282
> 

```

---

<div class="post-metadata">

**Author:** ![moebius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moebius/32/2872_2.png) [@moebius](https://discourse.nodered.org/u/moebius)\
**Post date:** [25 May 2019 09:20 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/9 "2019-05-25T09:20:02Z")

</div>

whats the output of:

```auto
select * from watts limit 5
```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [25 May 2019 09:44 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/10 "2019-05-25T09:44:52Z")

</div>

> [@zenofmud](#):
>
> you can use or not use the quotes

Yes, the quotes are required for names with spaces or other odd characters. Grafana puts them in for you anyway.

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [25 May 2019 09:50 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/11 "2019-05-25T09:50:46Z")

</div>

FYI - I have a very simple set up between node red and influxdb - just energy reading being sent. Appliance 0 is the energy monitor and the watts query is where I’m trying to pull values from

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/53ca1fe5f1511f05e36dc268bb5d733c2b18efa2.jpeg)

I’m looking to query my energy data and pull the following

The highest value ever  
The lowest value ever  
The mean value ever

Then , rather than pulling from ‘everything ’ - report the same thing again but by....

... the last hour  
... the last 12 hours  
... today  
... last week  
... last month

Here’s what the wildcard query returns .

`select * from Watts;`

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/82bfd7199565e1e645a99f200de2f063e4259a67.jpeg)

No idea if this is even possible but wanted to give it a try ..

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [25 May 2019 09:56 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/12 "2019-05-25T09:56:02Z")

</div>

> [@TotallyInformation](#):
>
> SELECT max("value") FROM "watts"

This also returns an [Empty] response ? 🙁

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [25 May 2019 10:03 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/13 "2019-05-25T10:03:23Z")

</div>

Case sensitive !!

Sorry, I should have checked the examples being shared

This one worked..

```auto
select max(value) from Watts

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/67c115fcc467122286c3dc3523d6edde25248fe6.jpeg)

With the above in mind, I now have some good working examples now..

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b362f1d43d6828e872a4dca98b34c3f97862d812.jpeg)

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [25 May 2019 21:14 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/14 "2019-05-25T21:14:58Z")

</div>

Thanks all for your help, I’ve been looking at the influx query language ([InfluxQL functions | InfluxDB OSS v1 Documentation](https://docs.influxdata.com/influxdb/v1.7/query_language/functions/#mean)) and my next challenge is to do the same query, but this time only during a specific time period.

So I tried a few things and this felt the most likely,

```auto
SELECT max(value) FROM Watts WHERE time >= '2019–05-23' and time <= '2019-05-24'

```

But sadly not, it returns the following error.

> "Error: Error from InfluxDB: invalid operation: time and \*influxql.StringLiteral are not compatible"

Has anyone successfully done a query specifying a day range ?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 May 2019 21:34 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/15 "2019-05-25T21:34:40Z")

</div>

my guess is you have to use the full date/time like  
`WHERE time >= '2019-05-23T00:00:00Z' AND time <= '2019-05-24T00:00:00Z'`

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [25 May 2019 21:42 UTC](https://discourse.nodered.org/t/influxdb-query-confusion/11520/16 "2019-05-25T21:42:58Z")

</div>

Many Thanks @zenofmud. that did it,

FYI - I also got this one to work too - to show me the highest in the last hour.

```auto
SELECT max(value) FROM Watts WHERE time >= now()-60m

```
