Query to find DISTINCT between array of objects in Cosmos DB [ SQL API ]

时间:2019-04-17 01:37:50

标签: distinct azure-cosmosdb azure-cosmosdb-sqlapi

I am using Azure Cosmos DB with SQL API and we need to find the DISTINCT values between array of objects in the same document. I have structured the collection in the following ways

  1. I have 2 main attribute RID and RNAME. In the first collection, I have only one document which contains all the RID and RNAME mapping in the array of objects.

"Details":[ { "RID":"1", "RNAME:"Car" }, { "RID":"1", "RNAME:"Car" }]

  1. In second collection, I have multiple documents for each RID and RNAME mapping.

    { "RID":"1", "RNAME:"Car" }

I am using Stored procedure and I need to know which one is a good way to get DISTINCT of RNAME using stored procedure.

Using first collection, I am not sure how to query to find DISTINCT RNAME between objects in the array. Using second collection. when I use the SQL editor, the distinct Query works but not sure how to put it in Stored procedure.

DISTINCT Values of RNAME

1 个答案:

答案 0 :(得分:0)

  

1。多个文档

使用sql:

select distinct c.RNAME from c
  

2。单个文档

使用sql:

SELECT distinct d.RNAME FROM c
join d in c.Details

enter image description here