# Is there a way to get the entities with all the attributes in one query?

**URL:** https://forum.typedb.com/t/is-there-a-way-to-get-the-entities-with-all-the-attributes-in-one-query/194
**Category:** TypeQL
**Created:** [6 September 2022 18:43 UTC](https://forum.typedb.com/t/is-there-a-way-to-get-the-entities-with-all-the-attributes-in-one-query/194 "2022-09-06T18:43:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mike](https://forum.typedb.com/u/mike)
#### Post date: [6 September 2022 18:43 UTC](https://forum.typedb.com/t/is-there-a-way-to-get-the-entities-with-all-the-attributes-in-one-query/194/1 "2022-09-06T18:43:13Z")

</div>

Hey team,

I’m struggling to get all the relations with attributes and without them in one query. Now it looks like I really need two:  
`match $x sub relation;` , `match $x sub relation; $x owns $attr;` and union them in the client code.

Is there an expression to do it in one query or is this a language limitation for now?

---

<div class="post-metadata">

### Author: ![krishnan](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/krishnan/32/36_2.png) [@krishnan](https://forum.typedb.com/u/krishnan)
#### Post date: [6 September 2022 18:48 UTC](https://forum.typedb.com/t/is-there-a-way-to-get-the-entities-with-all-the-attributes-in-one-query/194/2 "2022-09-06T18:48:01Z")

</div>

Wouldn’t `match $x sub relation;` return both relations with and without attributes?

I’d expect:  
`match $x sub relation; $x owns $attr;` to return only those with attributes.  
`match $x sub relation; not {$x owns $attr;};` to return only those with attributes.

---

<div class="post-metadata">

### Author: ![mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mike](https://forum.typedb.com/u/mike)
#### Post date: [7 September 2022 10:57 UTC](https://forum.typedb.com/t/is-there-a-way-to-get-the-entities-with-all-the-attributes-in-one-query/194/3 "2022-09-07T10:57:29Z")

</div>

> Wouldn’t `match $x sub relation;` return both relations with and without attributes?

Yes it would, but it won’t return any attributes at all. Speaking about union I meant that you should union list of all the relations and list of relations with attributes.

E.g.:

- rel1
- rel2
- rel3  
UNION
- rel1 owns name, date

---

<div class="post-metadata">

### Author: ![joshua](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/joshua/32/28_2.png) [@joshua](https://forum.typedb.com/u/joshua)
#### Post date: [7 September 2022 14:45 UTC](https://forum.typedb.com/t/is-there-a-way-to-get-the-entities-with-all-the-attributes-in-one-query/194/4 "2022-09-07T14:45:00Z")

</div>

Right now a `match` query always returns a “fixed size” of answers that is returned. As such, we don’t currently support returning one answer that contains a relation `$x` and another answer that contains `$x` and `$attr`…  
With the proposed introduction of optionals this kind of thing will be possible: [Allow retrieving attributes optionally, without filtering the query · Issue #6322 · vaticle/typedb · GitHub](https://github.com/vaticle/typedb/issues/6322)
