Get distinct values from MySQL JSON array

筅森魡賤 提交于 2020-01-02 06:36:12

问题


I got a MySQL data Table, with a JSON Column containing a list of Values:

CONSTRAINT_TABLE

 ID | CONSTRAINT_TYPE | CONSTRAINT_VALUES
----+-----------------+--------------------------------
 '2'| 'testtype'      |'[801, 751, 603, 753, 803]'
 ...| ...             | ...

What I want to have is a distinct, comma-seperated List of JSON-Values. I tried it with group_concat, but it applys to the arrays, not the single values.

SELECT group_concat(distinct constraint_values->>'$') 
FROM constraint_table c 
WHERE c.constraint_type = "testtype";

Actual result:

[801, 751, 603, 753, 803],[801, 751],[578, 66, 15],...

My target result:

801, 751, 603, 753, 803, 578, 66, 15 ...

without duplicates. As rows would be nice, too.

Ideas, anyone?

来源:https://stackoverflow.com/questions/39508478/get-distinct-values-from-mysql-json-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!