I am trying to join two Postgres queries for a The foreman report. I am trying to see which servers are assigned to puppet class 180
The first Query is:
select puppetclass_id , host_id from host_classes where puppetclass_id = 180
the results look as follows
puppetclass_id | host_id
----------------+---------
180 | 378
180 | 377
The Second Query is:
select id, name, operatingsystem_id, enabled from public.hosts
the results look as follows:
id | name | operatingsystem_id | enabled
-----+-----------------------------+--------------------+---------
404 | s4-somedevserver- 4r5 | 17 | t
411 | mob-omedevserver- 4r2 | 19 | t
I am trying to match the host_id of the first query and the id of the second query together, but remove duplicates. I have the below query, but it just displayes all our servers and not only servers matching puppetclass 180
SELECT DISTINCT id, name, operatingsystem_id
FROM
(SELECT puppetclass_id , host_id
FROM host_classes
WHERE puppetclass_id = 180) t
CROSS JOIN
(SELECT id, name, operatingsystem_id, enabled
FROM public.hosts) m
ORDER BY id
Any pointers in the right direction would be appreciated