MySQL - retrieve a value from another table if column is null MySQL - retrieve a value from another table if column is null sql sql

MySQL - retrieve a value from another table if column is null


Use IFNULL or COALESCE:

SELECT T1.ID, IFNULL(T1.name, T2.name) AS nameFROM firsttable T1LEFT JOIN secondtable T2ON T1.T2_id = T2.id


Use ISNULL for sql

SELECT T1.ID, ISNULL(T1.name, T2.name) AS nameFROM firsttable T1LEFT JOIN secondtable T2ON T1.T2_id = T2.id