# Cross-reference queries

**URL:** <https://forum.weaviate.io/t/cross-reference-queries/125>\
**Category:** Support\
**Created:** [June 2, 2023, 1:06pm UTC](https://forum.weaviate.io/t/cross-reference-queries/125 "2023-06-02T13:06:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpiabrantes](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/jpiabrantes/32/89_2.png) [@jpiabrantes](https://forum.weaviate.io/u/jpiabrantes)\
**Post date:** [June 2, 2023, 1:06pm UTC](https://forum.weaviate.io/t/cross-reference-queries/125/1 "2023-06-02T13:06:18Z")

</div>

My schema has a `Document` and a `Passage` class. The document has a name, date, url, and the passage has a text, a vector embedding, and it also refers to one document.

I want to retrieve the top k passages along with some properties from their docs, while ensuring the top only has one passage from a document. Something like,

```python
client.query
    .get(
        'Passage',
        ['text', {'document': ['date', 'name']}]
    )
    .with_near_vector({'vector': vector})
    .groupBy({path: 'document', objectsPerGroup: 1})
    .with_limit(k)
    .do()

```

This query does not work. Is it possible to do something like this?

---

<div class="post-metadata">

**Author:** ![jphwang](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/jphwang/32/38_2.png) [@jphwang](https://forum.weaviate.io/u/jphwang)\
**Post date:** [June 5, 2023, 12:19pm UTC](https://forum.weaviate.io/t/cross-reference-queries/125/2 "2023-06-05T12:19:06Z")

</div>

Hi @jpiabrantes

The syntax is a bit tricky for groupby for sure. So this query works (I just tried it on our demo instance). You should be able to edit that to suit your purpose.

Does that work?

```python
client = weaviate.Client(
    url="https://edu-demo.weaviate.network",
    auth_client_secret=weaviate.AuthApiKey(api_key="learn-weaviate"),
    additional_headers={
        "X-OpenAI-Api-Key": os.environ["OPENAI_APIKEY"],
    }
)

response = (
    client.query
    .get("JeopardyQuestion", ["question", "answer"])
    .with_near_text({"concepts": ["space travel"]})
    .with_group_by(
        groups=5,
        properties=["hasCategory"],
        objects_per_group=1,
    )
    .with_limit(10)
    .with_additional(
        """
        group {
          id
          count
          groupedBy { value path }
          maxDistance
          minDistance
          hits{
            question
            hasCategory {
              ... on JeopardyCategory {
                _additional {
                  id
                }
              }
            }
            _additional {
              id
              distance
            }
          }
        }
        """
    )
    .do()
)

print(response)

```
