# Find all host\_groups with hosts that have a specific tag

**URL:** <https://community.dynatrace.com/t/find-all-host-groups-with-hosts-that-have-a-specific-tag/40004>\
**Category:** DQL\
**Tags:** dql\
**Created:** [May 31, 2023, 2:03pm UTC](https://community.dynatrace.com/t/find-all-host-groups-with-hosts-that-have-a-specific-tag/40004 "2023-05-31T14:03:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sinisa\_zubic](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/sinisa_zubic/32/32498_2.png) [@sinisa\_zubic](https://community.dynatrace.com/u/sinisa_zubic)\
**Post date:** [May 31, 2023, 2:03pm UTC](https://community.dynatrace.com/t/find-all-host-groups-with-hosts-that-have-a-specific-tag/40004/1 "2023-05-31T14:03:34Z")

</div>

Hi there,How would one find all host\_groups with hosts that have a specific tag? Something like:

```c-mrkdwn__pre
fetch dt.entity.host_group
| filter in(id,[fetch dt.entity.host |filter matchesValue(tags,"MyTag")|fields id])

```

I still struggle a bit with DQL syntax…&nbsp; &nbsp;Do I need a FilterIn, a Lookup, etc?Best,  
Sini

---

<div class="post-metadata">

**Author:** ![stefan\_eggersto](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/stefan_eggersto/32/34114_2.png) [@stefan\_eggersto](https://community.dynatrace.com/u/stefan_eggersto)\
**Post date:** [June 1, 2023, 7:01am UTC](https://community.dynatrace.com/t/find-all-host-groups-with-hosts-that-have-a-specific-tag/40004/2 "2023-06-01T07:01:44Z")

</div>

You need to join the 2 tables using&nbsp;`lookup`&nbsp; and then do a filter. Please try following DQL:

```c-mrkdwn__pre
fetch dt.entity.host_group<br>| lookup [fetch dt.entity.host<br>| filter matchesPhrase(tags,"MyTag")<br>| fieldsAdd hostGroupReference = instance_of[dt.entity.host_group]], sourceField:id, lookupField:hostGroupReference<br>| filter isNotNull(lookup.id)<br>| fieldsRemove "lookup*"

```

Some explanation

- first fetch all host groups
- then do a lookup for hosts filtered by the tag.
- hosts are linked to the host groups by the field&nbsp;`instance_of[dt.entity.host_group]`
- then filter on hosts groups which have the field&nbsp;`lookup.id`&nbsp;. Basically filter only those host groups which have match from the lookup

---

<div class="post-metadata">

**Author:** ![SGOconnell1](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@SGOconnell1](https://community.dynatrace.com/u/SGOconnell1)\
**Post date:** [September 4, 2024, 7:44pm UTC](https://community.dynatrace.com/t/find-all-host-groups-with-hosts-that-have-a-specific-tag/40004/3 "2024-09-04T19:44:51Z")

</div>

How would one go about this using timeseries data? Same thing?

i.e. I have a query for disk space by a single host filter that works, but i want to leverage Host Group rather than dt.entity.host for my filter value.

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [September 5, 2024, 6:43pm UTC](https://community.dynatrace.com/t/find-all-host-groups-with-hosts-that-have-a-specific-tag/40004/4 "2024-09-05T18:43:25Z")

</div>

Even simpler then it was possible 1 year ago. E.g. to get disk usage for all disks of hosts in specific host group:

```markup
timeseries disk_used=max(dt.host.disk.used), 
  by:{dt.entity.host, dt.entity.disk}, 
  filter: {entityName(dt.entity.host_group)=="vmware"}

```

 ![krzysztof_hoja_0-1725561757501.png](https://global.discourse-cdn.com/dynatrace/original/2X/6/626070ebf61e061f4cc74584ebf1364c46f1b472.png)
