I have the following language table in MySQL for selecting text in different languages.
CREATE TABLE `lang` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `group` INT(10) UNSIGNED NOT NULL, `text` VARCHAR(255) NULL DEFAULT NULL, `language` VARCHAR(10) NOT NULL DEFAULT 'def', PRIMARY KEY (`id`), UNIQUE INDEX `group_language` (`group`, `language`) ) COLLATE='utf8_general_ci' ENGINE=InnoDB ROW_FORMAT=DEFAULT
The table contains the following data
id group text language 1 1 This is English def 2 2 Helo sir def 3 3 how are you? def 4 3 Wie geht es dir? de
The group field tells me which texts belong to each other for each translation. In the above example, group "3" has the default text (English) and German translation.
Now I want to select all the texts for the German language, and if they do not exist, I want to have a backup English text for this.
Does anyone know how I can combine this into an SQL query?
source share