Reputation:
I have two tables, that need to be joined. They look like this
I need to join them so I have all the data from both tables and then display the information like this - IF there is German translation, display ONLY German. If there is no German, display English (Which is available for all the objects)
Upvotes: 1
Views: 97
Reputation: 16487
SELECT f1.id,f1.lang,f1.name
FROM foo AS f1
LEFT JOIN foo AS f2
ON f1.id=f2.id AND f1.lang<>f2.lang AND f2.lang='ger'
WHERE f2.id IS NULL
http://sqlfiddle.com/#!2/a0a75/9
If there are more than just english and german language the last line should be changed to
WHERE f2.id IS NULL AND (f1.lang='ger' OR f1.lang='eng')
Upvotes: 1
Reputation:
Try:
select entry_id,
case max(lang)
when 'ger' then max(case lang when 'ger' then name end)
else max(name)
end as trans_name
from your_table
group by entry_id
Upvotes: 1
Reputation: 238078
select eng.entryid
, coalesce(ger.name, eng.name)
from YourTable eng
left join
YourTable ger
on ger.entryid = eng.entryid
and ger.lang = 'ger'
where eng.lang = 'eng'
Upvotes: 3