Dev Helpers

SQL / Joins

Zip labels with measurements by index

Dev Helpers · November 16, 2026

Two JSON arrays can be aligned by their integer indexes. An inner join will omit an unmatched tail.

Worked example

SELECT a.value AS label,b.value AS reading FROM json_each('["in","out"]') a JOIN json_each('[18,21]') b USING(key) ORDER BY a.key;

Result

[
  {
    "label": "in",
    "reading": 18
  },
  {
    "label": "out",
    "reading": 21
  }
]

Implementation notes

Joining on key rather than position requires a stable identifier on both sides. Aligning by index is correct only when the arrays share an ordering contract.

Try it yourself

Remove the last measurement and check whether the corresponding label disappears.

Open the SQL example →

Editorial date November 16, 2026 · Published December 6, 2026

Related articles

Compare two literal lists

Set operations compare rows under SQL's rules for duplicates. Check whether the result represents membership or the number of occurrences.

Count jobs per active day

Grouping timestamps by day produces counts only for days present in the data. A continuous chart may need a calendar series as well.

Read the previous duration

LAG retrieves a prior row's value within an ordered window. The first row lacks a predecessor and usually needs its own display rule.