Find the bugs: matching values from two sources

You have two tables, iv_t1 and iv_t2, and need to match their rows on x. A pair should match if the values are equal or both are missing. If one side has a missing value and the other has a value for x, the rows must not match. Keep every valid pair, including duplicates. Check the join condition and mark the incorrect lines.

Find the errorsNULLMiddleData EngineerBackendAnalyst
Input data · iv_t1
x
1
1
2
NULL
Input data · iv_t2
x
1
2
2
3
NULL
SELECT a.x AS x_left,
       b.x AS x_right
FROM iv_t1 AS a
INNER JOIN iv_t2 AS b
  ON COALESCE(a.x, 2) = COALESCE(b.x, 2)
ORDER BY CASE WHEN a.x IS NULL THEN 0 ELSE 1 END,
         a.x,
         CASE WHEN b.x IS NULL THEN 0 ELSE 1 END,
         b.x