You that three reference tables in one column. You can use multiple left join
s:
select c.*,
coalesce(lr.definition, br.definition, sr.definition) as reason
from containers c left join
loss_reasons lr
on c.reasonid = lr.reasonid left join
bonus_reasons br
on c.reasonid = br.reasonid left join
scrap_reasons sr
on c.reasonid = sr.reasonid;
I would recommend that you rethink the data model. Put all the reasons into a single table with a "category" for the reason.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…