mysql - Select values by one parameter and complete table with other -


really hard explain problem in title. have table of translations multiple languages in looks this

+---------------+----------------------------------+----------+ | name          | translation                      | language | +---------------+----------------------------------+----------+ | translation_1 | text translation n.1 | en       | +---------------+----------------------------------+----------+ | translation_2 | text translation n.2 | en       | +---------------+----------------------------------+----------+ | translation_3 | text translation n.2 | en       | +---------------+----------------------------------+----------+ | translation_2 | toto je text pre preklad č.2     | sk       | +---------------+----------------------------------+----------+ 

now need fetch translations language 'sk' can't sure there translations languages want achieve fetch language 'sk' , complete translations language 'en' (which default language , have translations).

this should result

+---------------+----------------------------------+----------+ | name          | translation                      | language | +---------------+----------------------------------+----------+ | translation_1 | text translation n.1 | en       | +---------------+----------------------------------+----------+ | translation_2 | toto je text pre preklad č.2     | sk       | +---------------+----------------------------------+----------+ | translation_3 | text translation n.2 | en       | +---------------+----------------------------------+----------+ 

thanks advice!

considering each translation exists "en", can do

select   en.name,   ifnull(sk.translation, en.translation) translation,   ifnull(sk.language, en.language) language translation en   left join translation sk on en.name = sk.name , sk.language = "sk" en.language = "en" 

you select english translations , left join swedish translations. translation , language column, state prefer swedish, otherwise english.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -