select *
from customers x, phones y
where x.customer_id = y.customer_id and primary = 'Y' union
( select *
from customer x, phones y
where x.customer_id = y.customer_id and primary != 'Y'
and x.customer_id not in ( select x.customer_id
from customers x, phones y
where x.customer_id = y.customer_id and primary = 'Y')
and rownum = 1
)