I am very surprised the bolded lines don't both cause syntax errors due to the space in the first bolded line and the lack of a column in the second.
select distinct
base_pats.pat_name,
base_pats.pat_id,
base_pats .filing_order,
base_pats.
prim.payor_name as Primary_Payor,
sec.payor_name as Secondary_Payor
from base_pats
That aside, help me understand what you are trying to do when Filing Order is 3. You want to display "MEDICARE" for both Primary and Secondary when Filing Order is 3?
Noel