Is there any way to join two tables like we join in MySQL like inner join , outer join etc
I want data from 2 tables on foreign key basis
Is there any way to join two tables like we join in MySQL like inner join , outer join etc
I want data from 2 tables on foreign key basis
EDIT: This answer is not relevant anymore since the OP's question was something totally different which I misunderstood!
Hi Rana Awais,
Can you provide more details on what you're trying to achieve? Which two tables are you trying to join? Are they sugar modules?
Yes, we can actually join two tables, though there are no foreign keys.
For plain relate fields, you can just join directly by using the IDs. Eg:
select * from cases c
join accounts a on c.account_id = a.id and a.deleted = 0
where c.deleted = 0;
For relationships, there is usually a join table, eg:
select * from contacts c
left join accounts_contacts ac on ac.contact_id = c.id and ac.deleted = 0
left join accounts a on ac.account_id = a.id and a.deleted = 0
where c.deleted = 0;
yes sugar modules
yes u can Do !
For your reference-:
$sqlobj ="select cs_c.number_c, cs_c.entity_c, cn.first_name,cn.id AS ContactID,cs.account_id,cs.assigned_user_id,cs.priority,cs.description,csrel.contacts_cases_1contacts_ida from cases cs
Inner join contacts_cases_1_c csrel ON cs.id=csrel.contacts_cases_1cases_idb
Inner Join contacts cn On cn.id=csre.contacts_cases_1contacts_ida
Inner Join cases_cstm cs_c On cs_c.id_c=cs.id
where csrel.contacts_cases_1cases_idb='".$id."' AND cs.deleted=0 AND cn.deleted=0";
$result = $GLOBALS['db']->query($sqlobj);
$row = $GLOBALS['db']->fetchByAssoc($result);
Print_r($row);
Thanks.
M kumar i am using curl request for that
$instance_url = getInstanceURL();
$filter_url = $instance_url . "/RELIC_Reseller_Quotes/filter";
$filter_arguments = array(
"max_num" => $rowsPerPage,
"offset" => $row,
"fields" => "id,name,quote_name_c,date_entered,reseller_id_c,secret_key_c,expiration_date_c,reseller_id_c,quote_number_c"
);
$filter_request = curl_init($filter_url);
curl_setopt($filter_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($filter_request, CURLOPT_HEADER, false);
curl_setopt($filter_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($filter_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($filter_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($filter_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
but i want reseller name and info which is saved in another module on the basis of reseller_id_c which is coming from above query
how can i do that?
SugarQuery offers handy wrappers to join across module, using the "link fields" to automatically relate two modules's SQL tables. You can read more about it here: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.1/Data_Framework/Database/SugarQuery/#Relationships
Restrain yourself from using direct SQL queries. While they might be "quicker" to put together (if you are not familiar with SugarQuery), it opens your solution up to problems (eg: SQL injection, portability across databases, missing a relevant parameter on the query to name a few)
--
Enrico Simonetti
Sugar veteran (from 2007)
Feel free to reach out for consulting regarding:
All active SugarCRM certifications
Actively working remotely with customers based in APAC and in the United States
from where i download sugarQuery?
i have posted the example in above message
please tell me how i can intergrate it with sugarQuery and from where i can download that sugarQuery.php
Rana Awais, your original question was about joining MySQL tables, so that's why I pointed you towards SugarQuery. Based on the question, I thought you wanted to build a custom api or functionality.
SugarQuery is included on Sugar's codebase.
There are many ways to achieve what you want to do. One example can be found here: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.1/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/
You could also bulk apis together so that you limit the number of http requests you make.
If you open your instance's /rest/v10/help url, you will get a help page on how to use our api as well.
--
Enrico Simonetti
Sugar veteran (from 2007)
Feel free to reach out for consulting regarding:
All active SugarCRM certifications
Actively working remotely with customers based in APAC and in the United States
Enrico Simonetti basically my question is how i can join 2 modules like in MYSQL have
I want data from 2 modules in single Query