Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL Seleziona le righe in base a una chiave o torna indietro per selezionare la chiave predefinita

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`