エイリアスがないため、クエリを追跡するのは困難です。私はそれが次のような構造になっていると仮定しています:
select a.one. b.two
from tableA a left join
tableb b
on a.id = b.id
where b.language = 'de'
order by xyz
以下は、MySQL で機能するはずのロジックを提供します。
SELECT a.one,
(case when (select COUNT(*) from b where b.id = a.id and b.language = 'de' and b.two is null) = 0
then bde.two
else bend.two
end) as two
FROM tableA A LEFT JOIN
tableB Bde
ON (A.id=B.id) and
bde.language='de' left join
tableB ben
on ben.language = 'en'
order by xyz
これは、NULL
値が B テーブルに格納されていることを前提としています。結合によって失われた場合は、次のように少し難しくなります。
SELECT a.one,
(case when (select COUNT(*) from a a2 join b b2 on a2.id = b2.id and b2.language = 'de' and b2.two is null) = 0
then bde.two
else bend.two
end) as two
FROM tableA A LEFT JOIN
tableB Bde
ON (A.id=B.id) and
bde.language='de' left join
tableB ben
on ben.language = 'en'
order by xyz