Query in cosmos db is not working

Gabriel Velandia 1 Reputation point
2021-08-13T17:09:45.423+00:00

hello I have the following query
SELECT device.Latitud, device.Longitud FROM device WHERE device.id IN (SELECT MAX(device.id) FROM device GROUP BY device.IMEI )

but ists no working if ai took the sentence SELECT device.Latitud, device.Longitud FROM device, it works and SELECT MAX(device.id) FROM device GROUP BY device.IMEI works

but i need the complete query

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,469 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anurag Sharma 17,576 Reputation points
    2021-08-16T07:38:16.42+00:00

    Hi @Gabriel Velandia , welcome to Microsoft Q&A forum.

    We need to refer to article to understand how sub-queries work in Azure Cosmos DB:
    Correlated: A subquery that references values from the outer query. The subquery is evaluated once for each row that the outer query processes.
    Non-correlated: A subquery that's independent of the outer query. It can be run on its own without relying on the outer query.

    Azure Cosmos DB supports only correlated subqueries.

    The sub-query mentioned the question is a non-correlated subquery.

    We need to run the sub query first and then that result can be used as an array and fire the second query individually.

    You can refer to below articles that mention the same behavior:

    Azure cosmos DB correlated subquery not working as expected

    Azure CosmosDB nested WHERE query

    Please let us know if this helps.

    ----------

    If answer helps, you can mark it 'Accept Answer'

    1 person found this answer helpful.
    0 comments No comments