En grundlæggende idé er at bruge 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;
Men hvis code
værdien er NULL
(eller en tom streng), skal du være mere forsigtig:
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)