postgresql7.3 select cc.curname, cc.codeA from (select coalesce(n.name, c.default_name) as curname, c.codeA from currencies c left outer join currency_names n on (c.codeA = n.codeA and language_code = :language)) cc order by lower(cc.curname)