AnsweredAssumed Answered

Need to convert this query to Sugar Query

Question asked by Madhav Shenoy on Sep 22, 2015
Latest reply on Oct 5, 2015 by meveridge
I need some help converting this query to SugarQuery . Please help

select phone_mobile from contacts a,contacts_cstm ac where a.phone_mobile is not null and a.deleted = 0and ac.id_c = a.id and ac.allow_sms_c = 1 
and exists (select 1 from prospect_lists b,prospect_lists_prospects c,prospect_list_campaigns d where b.list_type = 'default'
and b.id = c.prospect_list_id and c.related_type = 'Contacts' and c.related_id = a.id and b.deleted = 0 and c.deleted = 0
and d.prospect_list_id = b.id and d.deleted = 0 and d.campaign_id = '{$args["data"]}')
Union
Select phone_mobile from users a,users_cstm ac where a.phone_mobile is not null and a.deleted = 0
and ac.id_c = a.id and ac.allow_sms_c = 1 
and exists (select 1 from prospect_lists b,prospect_lists_prospects c,prospect_list_campaigns d where b.list_type = 'default'
and b.id = c.prospect_list_id and c.related_type = 'Users' and c.related_id = a.id and b.deleted = 0 and c.deleted = 0
and d.prospect_list_id = b.id and d.deleted = 0 and d.campaign_id = '{$args["data"]}')
Union
Select phone_mobile from prospects a,prospects_cstm ac where a.phone_mobile is not null and a.deleted = 0
and ac.id_c = a.id and ac.allow_sms_c = 1 
and exists (select 1 from prospect_lists b,prospect_lists_prospects c,prospect_list_campaigns d where b.list_type = 'default'
and b.id = c.prospect_list_id and c.related_type = 'Prospects' and c.related_id = a.id and b.deleted = 0 and c.deleted = 0
and d.prospect_list_id = b.id and d.deleted = 0 and d.campaign_id = '{$args["data"]}')

Outcomes