79584564

Date: 2025-04-21 11:50:08
Score: 2
Natty:
Report link

I have two queries that work in Cosmos. But now I want to combine them into one query. How do I do that?

As you want to combine the two queries, in the first query it is retrieving only the data which is "id = LanguageList-V3" and in the second query it is retrieving the data having languageId = "af". Means after combining two queries using JOIN, it will print only the data of id having LanguageList-V3 and with languageId = "af" .

Also, you mentioned There are other version of the same list in the table, below is the data stored in my cosmos db container with some other versions along with id "LanguageList-V3" such as "LanguageList-V1" and "LanguageList-V2":

[
    {
        "id": "LanguageList-V1",
        "type": "LanguageList",
        "version": 1,
        "createdAt": "2023-01-01T00:00:00Z",
        "Languages": [
            {
                "languageId": "af",
                "englishName": "Afrikaans",
                "nativeName": "Afrikaans",
                "active": true
            },
            {
                "languageId": "es",
                "englishName": "Spanish",
                "nativeName": "Español",
                "active": true
            }
        ]
    },
    {
        "id": "LanguageList-V2",
        "type": "LanguageList",
        "version": 2,
        "createdAt": "2024-01-01T00:00:00Z",
        "Languages": [
            {
                "languageId": "es",
                "englishName": "Spanish",
                "nativeName": "Español",
                "active": false
            },
            {
                "languageId": "zh",
                "englishName": "Chinese",
                "nativeName": "中文",
                "active": true
            }
        ]
    },
    {
        "id": "LanguageList-V3",
        "type": "LanguageList",
        "version": 3,
        "createdAt": "2025-04-21T12:00:00Z",
        "Languages": [
            {
                "languageId": "af",
                "englishName": "Afrikaans",
                "nativeName": "Afrikaans",
                "active": false
            },
            {
                "languageId": "zh",
                "englishName": "Chinese",
                "nativeName": "中文",
                "active": true
            }
        ]
    }
]

Below is the query which i tried to combine both the queries using JOIN:

SELECT VALUE l
FROM c
JOIN l IN c.Languages
WHERE c.id = "LanguageList-V3" AND l.languageId = "af"

Output:

[
    {
        "languageId": "af",
        "englishName": "Afrikaans",
        "nativeName": "Afrikaans",
        "active": false
    }
]

Note: Cosmos DB does not support joins across different containers or items. It supports self-join ,means joins occur within a single item. For more information, please refer to this link.

Reasons:
  • Blacklisted phrase (1): How do I
  • Blacklisted phrase (1): this link
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
Posted by: Balaji