select CASE WHEN owner_id = :user_id
THEN '\#contacts.My_Messages\#'
ELSE contact__name(owner_id) END,
owner_id
from ( select distinct owner_id
from contact_messages
where ( title is not null or owner_id = :user_id )
and owner_id in ( select party_id from parties )) distinct_owners
order by CASE WHEN owner_id = :user_id THEN '0000000000000000000' ELSE upper(contact__name(owner_id)) END
select item_id,
owner_id,
message_type,
title,
description,
content,
content_format,
locale
from contact_messages
where owner_id = :owner_id
order by message_type, upper(title)