Lets say i have this table
name | lang | message |
---|---|---|
welcome | en | Welcome, {user}!... |
welcome | ko | KoreanMessage1 |
error | en | Error occurred!.... |
error | ko | KoreanMessage2 |
so i want to select this table like this:
name | ko | en |
---|---|---|
welcome | KoreanMessage1 | Welcome, {user}!... |
error | KoreanMessage2 | Error occurred!... |
so how can i do this only with sql? (i'm using mariadb)
i tried this
(SELECT
a.name, a.value AS ko, b.value AS en
FROM messages AS a
LEFT JOIN messages AS b
ON a.name = b.name AND a.lang = 'ko' AND b.lang = 'en')
UNION
(SELECT
a.name, a.value AS ko, b.value AS en
FROM messages AS a
RIGHT JOIN messages AS b
ON a.name = b.name AND a.lang = 'ko' AND b.lang = 'en')
ORDER BY name ASC
(the table is "message")
and it didnt work. there was same columns twice.
oh and there might be some data that only in one language but i want to select that too with null on other language. for example like
name | ko | en |
---|---|---|
welcome | NULL | Welcome! ... |