select nebulae.*,if(Name='',concat('DITL Nebulae #',nebulae.ListID),Name) as Name,nebulaeimages.ImageName,refs.* from nebulae left join nebulaeimages on nebulaeimages.ListID=nebulae.ListID left join refs on refs.RefNumber=nebulae.Ref where nebulae.ListID=:Filter order by Name Asc;