AnsweredAssumed Answered

How can I translate my SQL query to an array?

Question asked by smeup smeup on Aug 4, 2014
Latest reply on Aug 26, 2014 by smeup smeup
I want to execute a slq query, bu I can't "translate" it into an array..

Here's sql:
[code]
SELECT T0.id, T0.name
FROM calls AS T0, accounts_opportunities AS T1
WHERE T0.parent_type = 'Opportunities' AND T1.opportunity_id = T0.parent_id AND T1.account_id = 'c6e6cf52-e380-9aeb-7da7-53c5133056ff'
UNION SELECT T0.id, T0.name
FROM calls AS T0, accounts_contacts AS T1
WHERE T0.parent_type = 'Contacts' AND T1.contact_id = T0.parent_id AND T1.account_id = 'c6e6cf52-e380-9aeb-7da7-53c5133056ff'
[/code]

What to do?
This

[code]
    $return_array['select'] = " SELECT T0.id, T0.name ";
    $return_array['from'] = " FROM calls AS T0, accounts_opportunities AS T1 ";
    $return_array['where'] = " WHERE T0.parent_type = 'Opportunities' AND T1.opportunity_id = T0.parent_id AND T1.account_id = 'c6e6cf52-e380-9aeb-7da7-53c5133056ff' ";
   
    $return_array['union'] = "UNION SELECT T0.id, T0.name FROM calls AS T0, accounts_contacts AS T1
    WHERE T0.parent_type = 'Contacts' AND T1.contact_id = T0.parent_id AND T1.account_id = 'c6e6cf52-e380-9aeb-7da7-53c5133056ff'
    UNION SELECT T0.id, T0.name FROM calls AS T0, accounts_cases AS T1
    WHERE T0.parent_type = 'Cases' AND T1.case_id = T0.parent_id AND T1.account_id = 'c6e6cf52-e380-9aeb-7da7-53c5133056ff' ";
[/code]

makes an error

Thanks

Outcomes