SELECT id, full_name, last_name, first_name, contact_type, entity_name, entity_id, position as title, email, phone, is_primary, company_type
     FROM (
         SELECT cc.id, 
                CONCAT(cc.first_name, " ", cc.last_name) as full_name,
                cc.last_name, cc.first_name,
                "company" as contact_type,
                COALESCE(c.company_name, CONCAT(c.first_name, " ", c.last_name)) as entity_name,
                c.id as entity_id,
                cc.position, cc.email, cc.phone, cc.is_primary,
                c.company_type
         FROM customer_contacts cc
         LEFT JOIN customers c ON cc.customer_id = c.id
         
         UNION ALL
         
         SELECT gc.id,
                CONCAT(gc.first_name, " ", gc.last_name) as full_name,
                gc.last_name, gc.first_name,
                "general" as contact_type,
                gc.company as entity_name,
                NULL as entity_id,
                gc.position, gc.email, gc.phone, 0 as is_primary,
                NULL as company_type
         FROM general_contacts gc
     ) all_contacts