Dev Helpers
← Back

Rebuild a deduplicated array in first-seen order

Rebuild a deduplicated array in first-seen order using SQLite JSON functions.

Open this example in the interactive library

Source code

WITH items AS (SELECT value,min(key) AS first_seen FROM json_each('["b","a","b","c"]') GROUP BY value) SELECT json_group_array(value ORDER BY first_seen) AS items FROM items;

Sample output

[
  {
    "items": "[\"b\",\"a\",\"c\"]"
  }
]