How to Join columns from two different tables from sql database and present it as a single table in grafana

Grafana version : V9.2.1 opensource
Database : MySQL

What am I trying to achieve?
I am trying to JOIN two tables which is having one common column for visualisation

How am I trying to achieve it?
I tried using SQL query inner join

[SELECT py.data.headid, py.data.duration, py.data.saporder, py.data.nofcu, py.header.week, py.header.version
FROM (py.data
INNER JOIN py.header ON py.data.headid = py.header.id)
ORDER BY id DESC LIMIT 50]

What happened?
I get an error with “db query error: query failed - please inspect Grafana server log for details”

What did I expect to happen?
The columns from two tables mentioned in the query in a single table

SELECT h.headid, d.duration, d.saporder, d.nofcu, h.week, h.version
FROM py.data d
INNER JOIN py.header h 
 ON d.headid = h.id
ORDER BY h.id DESC LIMIT 50
1 Like

@yosiasz Thank you so much for your solution query. Apologise me for my ignorance, I am newbie in coding query and data stuff. Your query gives me the solution. Can you also explain me the reason behind it so I can the understand it precisely?

1 Like

No problem. I would encourage you to take a quick tutorial of mysql on youtube or w3schools web site. So not sure what you mean when you say " the reason behind behind it"

When selecting from tables you do not need parentheses unless you are doing sone sort of subquery. And then you can, not must, use what are called aliases for table names to shorten your query syntax.