mysql query show multiple tables from one ID column

后端 未结 3 1072
青春惊慌失措
青春惊慌失措 2020-12-22 12:53

I\'m trying to find this query where I want to show which hosts uses which template from my Zabbix table. The only problem is that hosts and templates are registered in the

3条回答
  •  庸人自扰
    2020-12-22 13:56

    You have to join twice. Give the table different aliases so you can distinguish them.

    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
    

提交回复
热议问题