select a.*, case when a.type = 'executeUnit' then (select e.name from diqm_quality_executeunit e where e.id = a.reference) when a.type = 'analyzer' then (select e.name from diqm_quality_analyzer e where e.id = a.reference) else '' end name from diqm_quality_analyzerrelation a