title: I want to count unique key from json data which is stored in multiple rows
body: <p>I have multiple json rows in a table</p>
  
  <p>For Example</p>
  
  <pre><code>row1 -&gt; {"json_key_1":{"ele":"value"},"json_key2":{"ele":"value""}}
  
  row2 -&gt; {"json_key_10":{"ele":"value"},"json_key20":{"ele":"value""}}
  
  row3 -&gt; {"json_key_1":{"ele":"value"},"json_key20":{"ele":"value""}}
  
  row4 -&gt; {"json_key_2":{"ele":"value"},"json_key30":{"ele":"value""}}
  </code></pre>
  
  <p>In these four json row i have to count unique keys </p>
  
  <p>For eg. "json_key_2" which is exists in  row1->josn and row4->json</p>
  
  <p>So i want unique keys from all json by stored procedure or some Query 
  which should count these key only once even present in multiple json rows </p>
  
  <p>each key count only once json_key_1,json_key2,json_key_10,json_key_20,json_key_30</p>
  
  <p>in this example KEY COUNT Result should be : 5 </p>
  
  <p>IN MySQL 5.7 we have functions to perform operation on JSON</p>
  
  <p>like : json_merge(), json_length() how to use them to achive this result.</p>
  
  <p>Is this possible in MYSQL ?    </p>
  
  <p><strong>I have created a stored procedure to get result</strong> </p>
  
  <pre><code>SELECT `json_row` INTO @ar1
  FROM `table` 
  WHERE row_id=1;
  
  SELECT `json_row` INTO @ar2
  FROM `table` 
  WHERE row_id=2;
  
  SELECT `json_row` INTO @ar3
  FROM `table` 
  WHERE row_id=3;
  
  SELECT `json_row` INTO @ar4
  FROM `table` 
  WHERE row_id=4;
  
  SELECT json_merge(@ar1,@ar2,@ar3,@ar4) INTO @result;
  
  SELECT json_length(@result);
  </code></pre>
  
  <p>This Query return in result json_keys length which is : 5</p>
  
  <p>I want to improve this query</p>
  
  <p>Can anyone suggest how to make better select query because in this i am selecting each json_row one by one by row_id.</p>
  
  <p>But if i will use some user_id in where clause instead of row_id</p>
  
  <p>SELECT Query will return 4 rows of that user and then how will store 4 rows into variables to perform json_merge() and json_length().</p>