Вы должны выбрать поле, к которому вы присоединяетесь (contract
) во встроенных представлениях:
SELECT s1.key, s1.value, s2.value
FROM (
SELECT contract, key, value
FROM tbl
WHERE id = 1
) as s1
JOIN (
SELECT contract, key, value
FROM tbl
WHERE id = 2
) as s2
ON s1.contract = s2.contract