0

I'm having trouble creating the output from two Zabbix tables. I would like to output IP(interafce) and NAME(hosts) using HOSTID.

interface table

| hostid |       ip     |
|   1    |    1.1.1.1   |
|   2    |    8.8.8.8   |

hosts table

| hostid |        name   
|   1    |    test.server.1  |
|   2    |    test.server.2  |

So i would like something like this

| hostid |      ip       |      name
|   1    |    1.1.1.1    |  test.server.1  |
|   2    |    8.8.8.8    |  test.server.2  |

Thanks for you help

Jarvis
  • 23
  • 3

1 Answers1

0

Use a left join:

SELECT
    i.hostid,
    i.ip,
    COALESCE(h.name, 'NA') AS name
FROM interface i
LEFT JOIN hosts h
    ON h.hostid = i.hostid
ORDER BY
    i.hostid;
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360