sql >> Base de Datos >  >> RDS >> Mysql

MySQL Seleccione filas por una clave o retroceda para seleccionar por clave predeterminada

SELECT  DISTINCT
        COALESCE(b.ID, a.ID) ID,
        COALESCE(b.`GROUP`, a.`GROUP`) `GROUP`,
        COALESCE(b.`text`, a.`text`) `text`,
        COALESCE(b.language, a.language) language
FROM   TableName a
       LEFT JOIN
        (
            SELECT ID, `GROUP`, `text`, language
            FROM tableName
            WHERE language = 'de'
         ) b ON a.ID <> b.ID AND a.`GROUP` = b.`GROUP`