Jednym z podstawowych pomysłów jest użycie join
:
select t0.item_id, t0.code as code_0, t1.code as code_1
from t t0 join
t t1
on t0.item_id = t1.item_id and
t0.item_revision = 0 and
t1.item_revision = 1
where t0.code <> t1.code;
Jeśli jednak code
wartość to NULL
(lub pusty ciąg), musisz być bardziej ostrożny:
where t0.code <> t1.code or (t0.code is null and t1.code is not null) or
(t0.code is not null and t1.code is null)