SELECT t1.*, IF(t2.`student_id` IS NULL,'N','Y') customer_flag FROM (
(SELECT s.student_id, s.student_account_id, s.student_name, s.student_lastname, p.participant_first_name, p.participant_last_name
, IFNULL(p.participant_id,'') as member
FROM `student` s LEFT JOIN `participant` p ON p.`student_id` = s.`student_id`AND p.`company_id`=s.`company_id` AND p.registration_flag !='Q'
WHERE s.company_id = '3558' AND s.`deleted_flag`!='D' AND s.`registration_flag`!='Q'AND s.`student_account_id` IS NOT NULL and s.`student_id`= s.`student_account_id` and s.first_login_dt >0 GROUP BY s.`student_id`) t1
LEFT JOIN (SELECT DISTINCT `student_id` FROM `membership_registration` WHERE company_id=3558 and membership_status !='Q'
UNION
SELECT DISTINCT `student_id` FROM `event_registration` WHERE `company_id`=3558
UNION
SELECT DISTINCT `student_id` FROM `class_registration` WHERE `company_id`=3558
UNION
SELECT DISTINCT `student_id` FROM `trial_registration` WHERE `company_id`=3558
UNION
SELECT DISTINCT `student_id` FROM `retail_orders` WHERE `company_id`=3558
UNION
SELECT DISTINCT `student_id` FROM `misc_order` WHERE `company_id`=3558
)t2 on t1.student_id=t2.student_id) having member ='';