Home >Database >Mysql Tutorial >How to Retrieve Host and Template Names from Multiple Zabbix Tables Using a Single ID Column?
Query Multiple Tables from a Single ID Column
In a recent query, a user sought to display which hosts utilized specific templates from the Zabbix table. However, both hosts and templates were listed in the same table, creating a challenge in distinguishing them.
To address this issue, the user referenced a second table, hosts_templates, which provided the correlation between hosts and templates. The hosts_templates table, containing columns for host_template ID, host ID, and template ID, offered the data required for connecting the hosts and template names.
Solution
To achieve the desired output, a query with double joins is necessary:
SELECT h1.name as host_name, h2.name AS template_name FROM hosts_template AS t JOIN hosts AS h1 ON t.hostid = h1.hostid JOIN hosts AS h2 ON t.hosttemplateid = h2.hostid
In this query:
The above is the detailed content of How to Retrieve Host and Template Names from Multiple Zabbix Tables Using a Single ID Column?. For more information, please follow other related articles on the PHP Chinese website!