# JSON Sqlite database query .. 2 into 1?

**URL:** <https://discourse.nodered.org/t/json-sqlite-database-query-2-into-1/66673>\
**Category:** General\
**Created:** [19 August 2022 14:06 UTC](https://discourse.nodered.org/t/json-sqlite-database-query-2-into-1/66673 "2022-08-19T14:06:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [19 August 2022 14:06 UTC](https://discourse.nodered.org/t/json-sqlite-database-query-2-into-1/66673/1 "2022-08-19T14:06:15Z")

</div>

Hi, Sorry for asking here,but I have tried on a Sqlite forum and so far no answers. 😔  
But I know on here your are knowledgeable and some use JSON and SQlite.

I have a JSON SQLite database, at the moment I use 2 separate queries to extract the data.  
What I need is to have these as one single query made from the two below ?.  
The reason is that Grafana gives the Legend twice ?  
 ![04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7aebae70b41de37c2c5e55c39f74c7e9528b275d.png)

```auto

select 
json_extract( value, '$.Gas_reading' ) as Gas,
json_extract( value, '$.iso') as time 

from DATABASE, json_tree( DATABASE.data, '$.IP15' )
where type = 'object'
and json_extract( value, '$.Gas_reading' ) >= 0;

```

and the other one

```auto

select
json_extract( value, '$.Electricity_reading' ) as Electricity,
json_extract( value, '$.iso') as time

from DATABASE, json_tree( DATABASE.data, '$.IP22' )
where type = 'object'
and json_extract( value, '$.Electricity_reading' ) >= 0;

```

If this helps ...  
My Database setup  
 ![03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/a/aacc007b7f6a86c19ac07dc50a5601b560f0f4bb.png)

and the objects that are in the above Database DATA table.

 ![02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/2194e2f61e830e4ea3225fd0005ce6146ad36202.png)

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [19 August 2022 17:08 UTC](https://discourse.nodered.org/t/json-sqlite-database-query-2-into-1/66673/2 "2022-08-19T17:08:48Z")

</div>

I finally found out the answer, so just in case anyone else has this problem ...

> **[Legend appears twice ... when I have data sources on one graph?](https://community.grafana.com/t/legend-appears-twice-when-i-have-data-sources-on-one-graph/70780)**
>
> Hi, I am very new to Grafana, I have created a chart with one data source and the legend is shown correctly. I then created another chart with 2 data sources and now the legend shows … Electric Electric … it should only show Electric once. It may...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 September 2022 17:09 UTC](https://discourse.nodered.org/t/json-sqlite-database-query-2-into-1/66673/3 "2022-09-02T17:09:07Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
