# Joins and subqueries https://www.sanity.io/learn/course/between-groq-and-a-hard-place/joins-and-subqueries.md When a document contains a reference it only stores the ID of that document, GROQ can resolve it Try querying for an event document and return the venue reference. 1. Return the `venue` of every `event` ```groq *[_type == "event" && defined(venue)][0]{ venue } ``` The venue attribute will return a reference to another document's ID in the attribute `_ref`. You can “resolve” this reference with this operator `->` This deceptively simple operator will perform a “sub-query” to resolve the document with that `_id`. 1. Resolve the `venue` reference ```groq *[_type == "event" && defined(venue)][0]{ venue-> } ``` Excellent! We now have the actual details of the category document. But again, we have the “too much data” problem. This can be fixed by adding an additional projection. 1. Get only the `name` of the `venue` document ```groq *[_type == "event" && defined(venue)][0]{ venue->{ name } } ``` ## Reverse reference lookups It’s possible to create your own subquery anywhere in a document. However, you should be mindful that additional nesting and queries can increase response time and the volume of data. Exercise caution. References are one-way in that they are stored on a document. However the `references()` GROQ function allows you to look up all other references to a document ID. A useful sub-query for this project would be to look up every event when querying for an artist, like a reverse lookup of references. 1. Using the `references()` GROQ function, get every `event` featuring the current `artist`. ```groq *[_type == "artist"][0]{ name, "events": *[_type == "event" && references(^._id)]{ name } } ``` The `^` character traverses out of the current filter to access the "parent." In the above example, it is accessing the `_id` attribute of the artist document. 1. See [GROQ operators](https://www.sanity.io/learn/specifications/groq-operators) in the documentation for more details on what is available when writing GROQ queries 2. See [High Performance GROQ](https://www.sanity.io/docs/high-performance-groq) for more guidance on keeping queries performant