I have a table with a json field. The json schema is the same for all records.
I want to get just 2 products with red or blue color and with brand 1.
I tried the below query but I know that's not working:
SELECT [Id], [JName], [JValue]
FROM [Product]
CROSS APPLY OPENJSON([Json])
WITH ([JName] NVARCHAR(50) '$.name', [JValue] NVARCHAR(50) '$.value')
WHERE
(CASE WHEN [JName]=N'color' AND [JValue] IN (N'red', N'red') THEN 1 ELSE 0 END) &
(CASE WHEN [JName]=N'brand' AND [JValue] IN (N'brand 1') THEN 1 ELSE 0 END) = 1
so, how should I write this query?

CTEand in theSELECTclause you join to yourself. I have that code here, but I just wanted to clarify first about those two products.