2

I have a table [JsonTable], and the column [JsonData] save the json string,

JsonData like:

{
   "Content": [
      {
         "ContentId": "123",
         "Type": 1
      },
      {
         "ContentId": "456",
         "Type": 2
      }
   ]
}

or

[
     {
        "ContentId": "123",
        "Type": 1
     },
     {
        "ContentId": "456",
        "Type": 2
     }
]

How can I inner join like

SELECT* FROM [Content] AS C
INNER JOIN [JsonTable] AS J ON C.[Id] IN (SELECT value FROM OPENJSON(J.[JsonData],'$.Content.ContentId'))

1 Answer 1

1

You can use this query.

SELECT * FROM [Content] AS C
INNER JOIN [JsonTable] AS J ON C.[Id] IN (SELECT JSON_VALUE(value,'$.ContentId') 
                                          FROM OPENJSON(J.[JsonData],'$.Content'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.